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

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=VoQ0nvwkiVPQWih0V5J8kBSKKIrYhGiHateMYJD+Hqc=;
b=SwXlqwdpnaBfnCSWiOFtwGrirMxDPZvYQ1ZtVW0IBPs413texQ5cd2tNbN2agCY3c5
k5yU4H6gqSL3uYPwNOIRQBLzy7YX2D6M4aAR7yJEqFtQncskj4vCG6NYt9kLPIkt4Z67
ULWjQUMy2YaQJMovo/CwjES3FcZ9j/Pa3BeAUiVhENLz5kOTa1r1HScILIhM5dAQwOqa
YMDo6Vljzc1wPMsToXXcirDk/BbxCNQCvRd5D1kd5/hiLFi5OCFk34B4ADzywoQsqtxj
XsPr8m728oHzQuOv3xOZmD/OYEn8VPDl6pe/IDbEvnP4NOXuoywSwGYPZV9QlsHLw6jZ
8GEg==
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=VoQ0nvwkiVPQWih0V5J8kBSKKIrYhGiHateMYJD+Hqc=;
b=XsczUxPOaLuLDcRzg39G5tZaIHHA7kR6Rg/S6aEA2Bg50HoEy8ubQVdTERmDyeGYmO
z1cfwfHQKa14sO/e/vE3OhIb2FMjtL8lNhzw5iipUfty3JK4inOSXNkOOWNLbf3l44NZ
pN+D3GnSCsHE0TugS3aa5yHiAZG3ND6YHFuceFHicO2Pt4BeGwV4THA1C5IZe7cEPE+B
1bwHdCSvmMPdhynm3XPYllBsBVqXHJOPq9YJ1FMsiynPSD8rqS/KZ/PUjelCdhcg2jKI
O7dCqbWAkrzFq6nv/7fg3DTg4PECz739/zKjvIKZGuhrZwXSymqejQEQuOzXxm1cVHUZ
G+2w==
X-Gm-Message-State: AN3rC/5tEVMOsrbJMst80CeBzWzZ4DcP2Iw+kzvw9zObCn28Jqx/DtAJ
KCY482jsUV3YpH/FMM5MI1lZq9LkzQ==
X-Received: by 10.237.33.69 with SMTP id 63mr2313198qtc.251.1493407240268;
Fri, 28 Apr 2017 12:20:40 -0700 (PDT)
MIME-Version: 1.0
In-Reply-To: <CAA2C=vDKwsv7i5jNOGEpOEdokwsWbP3MV_eHU_M6s79cn=NkZg@mail.gmail.com>
References: <CAA2C=vC8s9Kg9LhewQmUMtiJNm+f=Gu5b-m_QXgiTgNufQQpfQ AT mail DOT gmail DOT com>
<CAA2C=vBNvQsBU+2_0JhJQqJr41pV=VWTUxgyS29VjUK6zL3paA AT mail DOT gmail DOT com> <CAA2C=vDKwsv7i5jNOGEpOEdokwsWbP3MV_eHU_M6s79cn=NkZg 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 22:20:39 +0300
Message-ID: <CAA2C=vC3EtQJmndPY7NRN_cSnDLbNpJPPM2FV6H4E9DcLoWgTg@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:
> On 4/28/17, Ozkan Sezer <sezeroz AT gmail DOT com> wrote:
>> 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?
[...]
>
> Just tested the above patch by generating out dxe and loading
> and running with it: works fine for me.
>

Here is a somewhat cleaned-up patch with a changelog entry:

dxe3gen.c: handle extended relocations. bump version to 1.0.4.

Index: src/docs/kb/wc206.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc206.txi,v
retrieving revision 1.3
diff -u -p -r1.3 wc206.txi
--- src/docs/kb/wc206.txi	26 Apr 2017 11:46:19 -0000	1.3
+++ src/docs/kb/wc206.txi	28 Apr 2017 18:11:10 -0000
@@ -3,6 +3,9 @@

 Here is a list of changes from DJGPP V2.05 to DJGPP V2.06

+@cindex dxe3gen and extended coff relocations
+dxe3gen now handles extended coff relocations (more than 65535 relocs.)
+
 @cindex Update of DXE linker script
 The dxe linker script, dxe.ld, now handles @code{.gnu.linkonce.b.*} and
 @code{.bss.*} sections.
Index: src/dxe/dxe3gen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/dxe/dxe3gen.c,v
retrieving revision 1.23
diff -u -p -r1.23 dxe3gen.c
--- src/dxe/dxe3gen.c	4 Oct 2015 10:27:26 -0000	1.23
+++ src/dxe/dxe3gen.c	28 Apr 2017 18:11:10 -0000
@@ -193,7 +193,7 @@
 #include "../../include/sys/dxe.h"
 #include "../../include/coff.h"

-#define VERSION  "1.0.3"
+#define VERSION  "1.0.4"

 #define TEMP_BASE    "dxe_tmp"       /* 7 chars, 1 char suffix */
 #define TEMP_O_FILE  TEMP_BASE".o"
@@ -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 */
@@ -985,9 +986,18 @@ static int write_dxe(FILE *inf, FILE *ou
   strings[0] = 0;

   /* Read the relocation table */
-  relocs = (RELOC *)malloc(sc.s_nreloc * sizeof(RELOC));
   fseek(inf, sc.s_relptr, SEEK_SET);
-  fread(relocs, RELSZ, sc.s_nreloc, inf);
+  if (sc.s_flags & STYP_NRELOC_OVFL) {
+    fread(&real_nrelocs, 4, 1, inf); /* read r_vaddr */
+    fseek(inf, RELSZ - 4, SEEK_CUR); /* skip the rest */
+    dh.nrelocs = --real_nrelocs; /* lose the '+1' */
+    if (opt.verbose)
+      printf("%s: real nrelocs: %lu\n", progname, (unsigned long)real_nrelocs);
+  } else {
+    real_nrelocs = dh.nrelocs;
+  }
+  relocs = (RELOC *)malloc(real_nrelocs * sizeof(RELOC));
+  fread(relocs, RELSZ, real_nrelocs, inf);

   /* Close input file */
   fclose(inf);
@@ -1042,7 +1052,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 +1111,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 +1212,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 +1288,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);


Any gotchas anyone can notice? Any comments and/or suggestions?
Should apply to CVS?

--
O.S.

- Raw text -


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