www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2017/04/28/05:43:15

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20161025;
h=mime-version:in-reply-to:references:from:date:message-id:subject:to;
bh=Q4EerPe5xivYSMbrjV9nAoyT/mkmbsA/y2IsVanOmV4=;
b=UGtaGDGmrQsqon2pW/mDyJ6V5l89aPOBIp8TNSWO56i+rESClCI3PR7iQ8eeccUNfl
4EqKukqrw7BOYKtfx/mN5GmywBGuvdrMhSvmKtJ1v/CWr4LSKIPOan0BVvqji1DIvm3b
KHGJlFZ5W6qY1tNC2GK5H4aPbZu/1Qb0S0sqpE9LQFaYVITdf7toF+GvGMubDDlefi7n
UixsislutqKBPN0QE/lFemiW7sBzLSqWqBTMEaNZRujn+ljPMaXljeRyoU9F2d7ly/ZB
Pen+Hef4Zy2p/vO3O6YEaLKPvw4KEAU6zUdMcmhwrQ/bFCYLyrYdfOarjV0581XGUo8C
/Gcw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:in-reply-to:references:from:date
:message-id:subject:to;
bh=Q4EerPe5xivYSMbrjV9nAoyT/mkmbsA/y2IsVanOmV4=;
b=XS81qr2DSJLAtEdIA/wXWf0M1jeI2Kz4udL2JFFteFIbeUJgGl6ZEAshMpQqamfF6f
aM8biCSmfBREVpV3cXHEgjdPZ6X5A2BnzwcqMxrcHZHWJdl6BS64MX/P+HptQ3bw0iXs
YUmALudnxfboJjKSeVqS3GqbNGWkA5900nqnYE1C2yH6f1X05HSoUYATmSLq9bVtGg8u
KYPIZ0QR3izyBIPnCj5w1fex9POxJgJ/yPFxLk5PZxaEPe2n6R5WzHKaac2/nMzHoGRa
WoCRc7LRSd5U6NXPkv8dcVJT9UP/eQ2TxGnqf9Ttpwvjq8BDWD3nmpWFvrZFt+thoF/S
WXzA==
X-Gm-Message-State: AN3rC/49Je4CWbeGUNoa1lvluvsTkXEn+4rT7iv5JxhrGi1+33S5AKfU
bfAozRzQ/kJtoRL3K9ILvjjOCKjvpw==
X-Received: by 10.200.4.26 with SMTP id v26mr4702597qtg.251.1493372586541;
Fri, 28 Apr 2017 02:43:06 -0700 (PDT)
MIME-Version: 1.0
In-Reply-To: <CAA2C=vC8s9Kg9LhewQmUMtiJNm+f=Gu5b-m_QXgiTgNufQQpfQ@mail.gmail.com>
References: <CAA2C=vC8s9Kg9LhewQmUMtiJNm+f=Gu5b-m_QXgiTgNufQQpfQ AT mail DOT gmail DOT com>
From: "Ozkan Sezer (sezeroz AT gmail DOT com) [via djgpp AT delorie DOT com]" <djgpp AT delorie DOT com>
Date: Fri, 28 Apr 2017 12:43:06 +0300
Message-ID: <CAA2C=vBNvQsBU+2_0JhJQqJr41pV=VWTUxgyS29VjUK6zL3paA@mail.gmail.com>
Subject: Re: dxe3gen does not handle relocs > 65535
To: djgpp AT delorie DOT com
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On 4/28/17, Ozkan Sezer <sezeroz AT gmail DOT com> wrote:
> dxe3gen does not handle extended relocations, i.e. STYP_NRELOC_OVFL
> set in hdr->s_flags: it still takes hdr->s_nreloc as number of relocs
> and ends up generating a broken dxe which leads to bad crashes when
> loaded.  We have one such c++ project where s_nreloc does overflow.
>
> I will be trying a few things with this, but I'd appreciate help or
> advice or links too:  How should I read the actual number of relocs?
> Would our current dlopen() still work with this?

Here is a dirty draft (to be tested yet). Comments?

Index: dxe3gen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/dxe/dxe3gen.c,v
retrieving revision 1.23
diff -u -p -r1.23 dxe3gen.c
--- dxe3gen.c	4 Oct 2015 10:27:26 -0000	1.23
+++ dxe3gen.c	28 Apr 2017 08:37:50 -0000
@@ -937,6 +937,7 @@ static int write_dxe(FILE *inf, FILE *ou
   char *strings;
   RELOC *relocs;
   unsigned int i, j, errcount;
+  ULONG32 real_nrelocs;
   size_t hdrsize;

   /* Exported symbols table */
@@ -953,7 +954,18 @@ static int write_dxe(FILE *inf, FILE *ou

   dh.magic = DXE_MAGIC;
   dh.element_size = -1;
-  dh.nrelocs = sc.s_nreloc;
+  if (sc.s_flags & STYP_NRELOC_OVFL) {
+    long pos = ftell(inf);
+    fseek(inf, sc.s_relptr, SEEK_SET);
+    /* r_vaddr is 1st member of struct external_reloc */
+    fread(&real_nrelocs, 4, 1, inf);
+    fseek(inf, pos, SEEK_SET);
+    dh.nrelocs = --real_nrelocs; /* remove the '+1' */
+    fprintf(stderr, "%s: real nrelocs: %u\n", progname, real_nrelocs);
+  }
+  else {
+    dh.nrelocs = real_nrelocs = sc.s_nreloc;
+  }
   dh.n_exp_syms = 0;
   dh.exp_table = sizeof(dh);
   dh.n_deps = opt.num_deps;
@@ -985,9 +997,12 @@ static int write_dxe(FILE *inf, FILE *ou
   strings[0] = 0;

   /* Read the relocation table */
-  relocs = (RELOC *)malloc(sc.s_nreloc * sizeof(RELOC));
+  relocs = (RELOC *)malloc(real_nrelocs * sizeof(RELOC));
   fseek(inf, sc.s_relptr, SEEK_SET);
-  fread(relocs, RELSZ, sc.s_nreloc, inf);
+  if (sc.s_flags & STYP_NRELOC_OVFL) {
+    fseek(inf, RELSZ, SEEK_CUR); /* skip the extra one. */
+  }
+  fread(relocs, RELSZ, real_nrelocs, inf);

   /* Close input file */
   fclose(inf);
@@ -1042,7 +1057,7 @@ static int write_dxe(FILE *inf, FILE *ou
       int n_abs_relocs = 0, n_rel_relocs = 0;

       /* count the amount of relocations pointing to this symbol */
-      for (j = 0; j < sc.s_nreloc; j++)
+      for (j = 0; j < real_nrelocs; j++)
       {
         if (relocs[j].r_symndx == i)
         {
@@ -1101,7 +1116,7 @@ static int write_dxe(FILE *inf, FILE *ou

       unres_size = newsize;

-      for (j = 0; j < sc.s_nreloc; j++)
+      for (j = 0; j < real_nrelocs; j++)
       {
         if (relocs[j].r_symndx == i)
         {
@@ -1202,7 +1217,7 @@ static int write_dxe(FILE *inf, FILE *ou

   /* Compute the amount of valid relocations */
   DEBUG_PRINT_RELOCATION_DIRECTIVE_PROLOG();
-  for (i = 0; i < sc.s_nreloc; i++)
+  for (i = 0; i < real_nrelocs; i++)
   {
     DEBUG_PRINT_RELOCATION_DIRECTIVE(i, relocs);
     if (!VALID_RELOC(relocs[i]))
@@ -1278,7 +1293,7 @@ static int write_dxe(FILE *inf, FILE *ou
   free(data);

   /* Output the relocations */
-  for (i = 0; i < sc.s_nreloc; i++)
+  for (i = 0; i < real_nrelocs; i++)
   {
     if (VALID_RELOC(relocs[i]))
       fwrite(&relocs[i].r_vaddr, 1, sizeof(relocs[0].r_vaddr), outf);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019