This is the mail archive of the gdb-prs@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pending/1132: RFC: coffread.c relocation fixes


>Number:         1132
>Category:       pending
>Synopsis:       RFC: coffread.c relocation fixes
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   unknown
>Arrival-Date:   Fri Mar 07 19:28:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        
>Organization:
>Environment:
>Description:
 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_01AE_01C2DDC6.A30370D0
 Content-Type: text/plain;
 	charset="iso-8859-1"
 Content-Transfer-Encoding: 7bit
 
 When a shared object can't be loaded at its preferred image base, it
 gets relocated. There's a convoluted switch statement in
 coff_symtab_read that handles relocation of the symbols, and I believe
 it handles a couple of cases incorrectly:
 
 o Static symbols (with c_sclass of C_STAT) never get relocated. I
 think this is wrong, probably an oversight where the C_STAT cases fall
 through to the C_EXT case and then don't get handled.
 
 o Absolute symbols (with c_secnum of N_ABS) *do* get relocated, so
 things like __minor_os_version__ get adjusted by the relocation
 offset. Curiously, there is a fixme comment in the code not to do
 this.
 
 The attached exmple shows the problem in action and the attached diffs
 fix both problems. Do these changes seem sensible to others?
 
 Regards,
 Raoul Gough.
 
 ------=_NextPart_000_01AE_01C2DDC6.A30370D0
 Content-Type: text/plain;
 	name="ChangeLog_entry.txt"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="ChangeLog_entry.txt"
 
 2003-02-26  Raoul Gough  <RaoulGough at yahoo dot co dot uk>
 
  	* coffread.c(coff_symtab_read): DO relocate static symbols from PE
 	files, DON'T relocate absolute symbols (and DO use mst_abs).
 
 ------=_NextPart_000_01AE_01C2DDC6.A30370D0
 Content-Type: text/plain;
 	name="coffread.c.diff.txt"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="coffread.c.diff.txt"
 
 Index: src/gdb/coffread.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /cvs/src/src/gdb/coffread.c,v
 retrieving revision 1.37
 diff -c -p -r1.37 coffread.c
 *** src/gdb/coffread.c	25 Feb 2003 21:36:17 -0000	1.37
 --- src/gdb/coffread.c	26 Feb 2003 18:37:26 -0000
 *************** coff_symtab_read (long symtab_offset, un
 *** 869,875 ****
   	       print_address_symbolic work right without the (now
   	       gone) "set fast-symbolic-addr off" kludge.  */
  =20
 - 	    /* FIXME: should use mst_abs, and not relocate, if absolute.  */
   	    enum minimal_symbol_type ms_type;
   	    int sec;
  =20
 --- 869,874 ----
 *************** coff_symtab_read (long symtab_offset, un
 *** 891,902 ****
   		  || cs->c_sclass =3D=3D C_THUMBEXT ?
   		  mst_bss : mst_file_bss;
   	      }
   	    else
   	      {
   		sec =3D cs_to_section (cs, objfile);
   		tmpaddr =3D cs->c_value;
 ! 		if (cs->c_sclass =3D=3D C_EXT || cs->c_sclass =3D=3D C_THUMBEXTFUNC
 ! 		    || cs->c_sclass =3D=3D C_THUMBEXT)
   		  tmpaddr +=3D ANOFFSET (objfile->section_offsets, sec);
  =20
   		if (sec =3D=3D SECT_OFF_TEXT (objfile))
 --- 890,913 ----
   		  || cs->c_sclass =3D=3D C_THUMBEXT ?
   		  mst_bss : mst_file_bss;
   	      }
 + 	    else if (cs->c_secnum =3D=3D N_ABS)
 + 	      {
 + 		/* Use the correct minimal symbol type (and don't
 + 		   relocate) for absolute vaules. */
 + 		ms_type =3D mst_abs;
 + 		sec =3D cs_to_section (cs, objfile);
 + 		tmpaddr =3D cs->c_value;
 + 	      }
   	    else
   	      {
   		sec =3D cs_to_section (cs, objfile);
   		tmpaddr =3D cs->c_value;
 !=20
 ! 		/* Statics in a PE file also get relocated */
 ! 		if (cs->c_sclass =3D=3D C_EXT
 ! 		    || cs->c_sclass =3D=3D C_THUMBEXTFUNC
 ! 		    || cs->c_sclass =3D=3D C_THUMBEXT
 ! 		    || (pe_file && (cs->c_sclass =3D=3D C_STAT)))
   		  tmpaddr +=3D ANOFFSET (objfile->section_offsets, sec);
  =20
   		if (sec =3D=3D SECT_OFF_TEXT (objfile))
 
 ------=_NextPart_000_01AE_01C2DDC6.A30370D0
 Content-Type: text/plain;
 	name="example3.txt"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="example3.txt"
 
 $ cat dlleg.c
 __attribute((__dllexport__)) void fn () { }
 static int local;
 
 $ cat dlleg2.c
 __attribute((__dllexport__)) void fn2 () { }
 static int local;
 
 $ cat dllegmain.c
 __attribute((__dllimport__)) void fn ();
 __attribute((__dllimport__)) void fn2 ();
 
 int main ()
 {
   fn();
   fn2();
 
   return 0;
 }
 
 $ gcc -g -c dlleg.c
 $ gcc -g -c dlleg2.c
 $ gcc -g -c dllegmain.c
 $ #
 $ # Force clash by omitting -Wl,--enable-auto-image-base
 $ #
 $ gcc -shared -o dlleg.dll dlleg.o
 $ gcc -shared -o dlleg2.dll dlleg2.o
 $ gcc -o dllegmain dllegmain.o dlleg.dll dlleg2.dll
 $ gdb dllegmain
 GNU gdb 2003-02-26-cvs
 Copyright 2003 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and you =
 are
 welcome to change it and/or distribute copies of it under certain =
 conditions.
 Type "show copying" to see the conditions.
 There is absolutely no warranty for GDB.  Type "show warranty" for =
 details.
 This GDB was configured as "i686-pc-cygwin"...
 (gdb) run
 Starting program: /cygdrive/f/Users/Raoul/gdb/dllegmain.exe=20
 
 Program exited with code 01.
 (gdb) #
 (gdb) # DLL info shows that dlleg and dlleg2 were loaded at different
 (gdb) # addresses, so one got relocated:
 (gdb) #
 (gdb) info dll
 
 DLL Name                                 Load Address
 /usr/bin/cygwin1.dll                     61001000
 /cygdrive/f/WINNT/system32/kernel32.dll  77e81000
 /cygdrive/f/Users/Raoul/gdb/dlleg2.dll   10001000
 /cygdrive/f/Users/Raoul/gdb/dlleg.dll    00331000
 /cygdrive/f/WINNT/system32/advapi32.dll  77db1000
 /cygdrive/f/WINNT/system32/rpcrt4.dll    77d41000
 /cygdrive/f/WINNT/System32/psapi.dll     690a1000
 (gdb) #
 (gdb) # Dump internal symbol tables
 (gdb) #
 (gdb) maint print msymbols reloc.dump
 (gdb) quit
 
 $ #
 $ # There should be two distinct static_int vars (one
 $ # relocated). Unpatches gdb doesn't get this right:
 $ #
 $ grep static_int reloc.dump
 [96] d 0x10005020 static_int
 [115] d 0x10005020 static_int
 
 $ #
 $ # ... and absolute values shouldn't be relocated but are:
 $ #
 $ grep os_version reloc.dump
 [ 3] T 0x0 _minor_os_version__
 [ 7] T 0x4 _major_os_version__
 [ 3] T 0x0 _minor_os_version__
 [ 7] T 0x4 _major_os_version__
 [127] T 0xf0330000 _minor_os_version__
 [131] T 0xf0330004 _major_os_version__
 
 $ #
 $ # with the patch, static vars are relocated correctly:
 $ #
 $ grep static_int reloc2.dump
 [96] d 0x10005020 static_int
 [95] d 0x335020 static_int
 
 $ #
 $ # ... and absolute variables are untouched (note also the "A"
 $ # type for the minimal symbols instead of "T")
 $ #
 $ grep os_version reloc2.dump
 [ 3] A 0x0 _minor_os_version__
 [ 7] A 0x4 _major_os_version__
 [ 3] A 0x0 _minor_os_version__
 [ 7] A 0x4 _major_os_version__
 [ 3] A 0x0 _minor_os_version__
 [ 7] A 0x4 _major_os_version__
 
 ------=_NextPart_000_01AE_01C2DDC6.A30370D0--
 
 
 
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]