* RFC: coffread.c relocation fixes
@ 2003-02-26 18:40 Raoul Gough
2003-04-03 21:48 ` Elena Zannoni
0 siblings, 1 reply; 8+ messages in thread
From: Raoul Gough @ 2003-02-26 18:40 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 791 bytes --]
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.
[-- Attachment #2: ChangeLog_entry.txt --]
[-- Type: text/plain, Size: 182 bytes --]
2003-02-26 Raoul Gough <RaoulGough@yahoo.co.uk>
* coffread.c(coff_symtab_read): DO relocate static symbols from PE
files, DON'T relocate absolute symbols (and DO use mst_abs).
[-- Attachment #3: coffread.c.diff.txt --]
[-- Type: text/plain, Size: 1885 bytes --]
Index: src/gdb/coffread.c
===================================================================
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. */
- /* FIXME: should use mst_abs, and not relocate, if absolute. */
enum minimal_symbol_type ms_type;
int sec;
--- 869,874 ----
*************** coff_symtab_read (long symtab_offset, un
*** 891,902 ****
|| cs->c_sclass == C_THUMBEXT ?
mst_bss : mst_file_bss;
}
else
{
sec = cs_to_section (cs, objfile);
tmpaddr = cs->c_value;
! if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
! || cs->c_sclass == C_THUMBEXT)
tmpaddr += ANOFFSET (objfile->section_offsets, sec);
if (sec == SECT_OFF_TEXT (objfile))
--- 890,913 ----
|| cs->c_sclass == C_THUMBEXT ?
mst_bss : mst_file_bss;
}
+ else if (cs->c_secnum == N_ABS)
+ {
+ /* Use the correct minimal symbol type (and don't
+ relocate) for absolute vaules. */
+ ms_type = mst_abs;
+ sec = cs_to_section (cs, objfile);
+ tmpaddr = cs->c_value;
+ }
else
{
sec = cs_to_section (cs, objfile);
tmpaddr = cs->c_value;
!
! /* Statics in a PE file also get relocated */
! if (cs->c_sclass == C_EXT
! || cs->c_sclass == C_THUMBEXTFUNC
! || cs->c_sclass == C_THUMBEXT
! || (pe_file && (cs->c_sclass == C_STAT)))
tmpaddr += ANOFFSET (objfile->section_offsets, sec);
if (sec == SECT_OFF_TEXT (objfile))
[-- Attachment #4: example3.txt --]
[-- Type: text/plain, Size: 2807 bytes --]
$ 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
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__
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: RFC: coffread.c relocation fixes
2003-02-26 18:40 RFC: coffread.c relocation fixes Raoul Gough
@ 2003-04-03 21:48 ` Elena Zannoni
2003-04-07 11:54 ` Raoul Gough
2003-05-12 16:38 ` Raoul Gough
0 siblings, 2 replies; 8+ messages in thread
From: Elena Zannoni @ 2003-04-03 21:48 UTC (permalink / raw)
To: Raoul Gough; +Cc: gdb-patches
Raoul Gough writes:
> 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?
I am not a coff expert, but the change seems sensible.
See below for a typo.
Did you run the gdb testsuite with your patch and w/o? Any differences?
elena
>
> Regards,
> Raoul Gough.
> 2003-02-26 Raoul Gough <RaoulGough@yahoo.co.uk>
>
> * coffread.c(coff_symtab_read): DO relocate static symbols from PE
> files, DON'T relocate absolute symbols (and DO use mst_abs).
> Index: src/gdb/coffread.c
> ===================================================================
> 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. */
>
> - /* FIXME: should use mst_abs, and not relocate, if absolute. */
> enum minimal_symbol_type ms_type;
> int sec;
>
> --- 869,874 ----
> *************** coff_symtab_read (long symtab_offset, un
> *** 891,902 ****
> || cs->c_sclass == C_THUMBEXT ?
> mst_bss : mst_file_bss;
> }
> else
> {
> sec = cs_to_section (cs, objfile);
> tmpaddr = cs->c_value;
> ! if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
> ! || cs->c_sclass == C_THUMBEXT)
> tmpaddr += ANOFFSET (objfile->section_offsets, sec);
>
> if (sec == SECT_OFF_TEXT (objfile))
> --- 890,913 ----
> || cs->c_sclass == C_THUMBEXT ?
> mst_bss : mst_file_bss;
> }
> + else if (cs->c_secnum == N_ABS)
> + {
> + /* Use the correct minimal symbol type (and don't
> + relocate) for absolute vaules. */
^^^^^ typo
> + ms_type = mst_abs;
> + sec = cs_to_section (cs, objfile);
> + tmpaddr = cs->c_value;
> + }
> else
> {
> sec = cs_to_section (cs, objfile);
> tmpaddr = cs->c_value;
> !
> ! /* Statics in a PE file also get relocated */
> ! if (cs->c_sclass == C_EXT
> ! || cs->c_sclass == C_THUMBEXTFUNC
> ! || cs->c_sclass == C_THUMBEXT
> ! || (pe_file && (cs->c_sclass == C_STAT)))
> tmpaddr += ANOFFSET (objfile->section_offsets, sec);
>
> if (sec == SECT_OFF_TEXT (objfile))
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: RFC: coffread.c relocation fixes
2003-04-03 21:48 ` Elena Zannoni
@ 2003-04-07 11:54 ` Raoul Gough
2003-05-12 16:38 ` Raoul Gough
1 sibling, 0 replies; 8+ messages in thread
From: Raoul Gough @ 2003-04-07 11:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Elena Zannoni
"Elena Zannoni" <ezannoni@redhat.com> wrote in message
news:16012.44364.781796.157557@localhost.redhat.com...
> Raoul Gough writes:
> > 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?
>
> I am not a coff expert, but the change seems sensible.
> See below for a typo.
> Did you run the gdb testsuite with your patch and w/o? Any
differences?
>
> elena
I'm still not geared up to run the test suites (I guess I just need to
install dejagnu). Will try to manage this by the end of the week, and
report back...
Will fix the typo as well - thanks!
--
Raoul Gough
see http://home.clara.net/raoulgough/ for my work availability
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RFC: coffread.c relocation fixes
2003-04-03 21:48 ` Elena Zannoni
2003-04-07 11:54 ` Raoul Gough
@ 2003-05-12 16:38 ` Raoul Gough
2003-05-23 16:19 ` Elena Zannoni
1 sibling, 1 reply; 8+ messages in thread
From: Raoul Gough @ 2003-05-12 16:38 UTC (permalink / raw)
To: gdb-patches; +Cc: Elena Zannoni
[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]
"Elena Zannoni" <ezannoni@redhat.com> wrote in message
news:16012.44364.781796.157557@localhost.redhat.com...
> Raoul Gough writes:
[snip]
> > The attached exmple shows the problem in action and the attached
diffs
> > fix both problems. Do these changes seem sensible to others?
>
> I am not a coff expert, but the change seems sensible.
> See below for a typo.
> Did you run the gdb testsuite with your patch and w/o? Any
differences?
I've checked my coffread.c patches against the testsuite, without
finding any regressions under Cygwin or Linux (not COFF based, so
there wouldn't be any changes expected, of course). I've also written
a new testsuite script that demonstrates the problem and tests the
fix. I've added the script as a note to PR 1132 in GNATS (see
http://sources.redhat.com/ml/gdb-prs/2003-q2/msg00129.html).
I've attached an updated diff to this posting with a fix for the typo
that Elena identified. Any advice on getting these patches checked in
and the PR closed? I can't do it myself, since I don't have any write
access.
Regards,
Raoul Gough
[-- Attachment #2: coffread.c.diff.txt --]
[-- Type: text/plain, Size: 1861 bytes --]
Index: coffread.c
===================================================================
RCS file: /cvs/src/src/gdb/coffread.c,v
retrieving revision 1.37
diff -c -p -r1.37 coffread.c
*** coffread.c 25 Feb 2003 21:36:17 -0000 1.37
--- coffread.c 12 May 2003 16:29:47 -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. */
- /* FIXME: should use mst_abs, and not relocate, if absolute. */
enum minimal_symbol_type ms_type;
int sec;
--- 869,874 ----
*************** coff_symtab_read (long symtab_offset, un
*** 891,902 ****
|| cs->c_sclass == C_THUMBEXT ?
mst_bss : mst_file_bss;
}
else
{
sec = cs_to_section (cs, objfile);
tmpaddr = cs->c_value;
! if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
! || cs->c_sclass == C_THUMBEXT)
tmpaddr += ANOFFSET (objfile->section_offsets, sec);
if (sec == SECT_OFF_TEXT (objfile))
--- 890,913 ----
|| cs->c_sclass == C_THUMBEXT ?
mst_bss : mst_file_bss;
}
+ else if (cs->c_secnum == N_ABS)
+ {
+ /* Use the correct minimal symbol type (and don't
+ relocate) for absolute values. */
+ ms_type = mst_abs;
+ sec = cs_to_section (cs, objfile);
+ tmpaddr = cs->c_value;
+ }
else
{
sec = cs_to_section (cs, objfile);
tmpaddr = cs->c_value;
!
! /* Statics in a PE file also get relocated */
! if (cs->c_sclass == C_EXT
! || cs->c_sclass == C_THUMBEXTFUNC
! || cs->c_sclass == C_THUMBEXT
! || (pe_file && (cs->c_sclass == C_STAT)))
tmpaddr += ANOFFSET (objfile->section_offsets, sec);
if (sec == SECT_OFF_TEXT (objfile))
[-- Attachment #3: ChangeLog_entry.txt --]
[-- Type: text/plain, Size: 182 bytes --]
2003-02-26 Raoul Gough <RaoulGough@yahoo.co.uk>
* coffread.c(coff_symtab_read): DO relocate static symbols from PE
files, DON'T relocate absolute symbols (and DO use mst_abs).
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: RFC: coffread.c relocation fixes
2003-05-12 16:38 ` Raoul Gough
@ 2003-05-23 16:19 ` Elena Zannoni
2003-05-28 15:04 ` Raoul Gough
0 siblings, 1 reply; 8+ messages in thread
From: Elena Zannoni @ 2003-05-23 16:19 UTC (permalink / raw)
To: Raoul Gough; +Cc: gdb-patches, Elena Zannoni, mec
Raoul Gough writes:
> "Elena Zannoni" <ezannoni@redhat.com> wrote in message
> news:16012.44364.781796.157557@localhost.redhat.com...
> > Raoul Gough writes:
> [snip]
> > > The attached exmple shows the problem in action and the attached
> diffs
> > > fix both problems. Do these changes seem sensible to others?
> >
> > I am not a coff expert, but the change seems sensible.
> > See below for a typo.
> > Did you run the gdb testsuite with your patch and w/o? Any
> differences?
>
> I've checked my coffread.c patches against the testsuite, without
> finding any regressions under Cygwin or Linux (not COFF based, so
> there wouldn't be any changes expected, of course). I've also written
> a new testsuite script that demonstrates the problem and tests the
> fix. I've added the script as a note to PR 1132 in GNATS (see
> http://sources.redhat.com/ml/gdb-prs/2003-q2/msg00129.html).
>
I don't have much comments on the test (except that the convention is
to use '-' instead of '_' in file names, and that you need to update
the gdb/config/djgpp/fnchange.lst file). I wonder if instead of 'while 1'
you could use exp_continue. MichaelC?
> I've attached an updated diff to this posting with a fix for the typo
> that Elena identified. Any advice on getting these patches checked in
> and the PR closed? I can't do it myself, since I don't have any write
> access.
>
I can commit it for you.
elena
> Regards,
> Raoul Gough
> Index: coffread.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/coffread.c,v
> retrieving revision 1.37
> diff -c -p -r1.37 coffread.c
> *** coffread.c 25 Feb 2003 21:36:17 -0000 1.37
> --- coffread.c 12 May 2003 16:29:47 -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. */
>
> - /* FIXME: should use mst_abs, and not relocate, if absolute. */
> enum minimal_symbol_type ms_type;
> int sec;
>
> --- 869,874 ----
> *************** coff_symtab_read (long symtab_offset, un
> *** 891,902 ****
> || cs->c_sclass == C_THUMBEXT ?
> mst_bss : mst_file_bss;
> }
> else
> {
> sec = cs_to_section (cs, objfile);
> tmpaddr = cs->c_value;
> ! if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
> ! || cs->c_sclass == C_THUMBEXT)
> tmpaddr += ANOFFSET (objfile->section_offsets, sec);
>
> if (sec == SECT_OFF_TEXT (objfile))
> --- 890,913 ----
> || cs->c_sclass == C_THUMBEXT ?
> mst_bss : mst_file_bss;
> }
> + else if (cs->c_secnum == N_ABS)
> + {
> + /* Use the correct minimal symbol type (and don't
> + relocate) for absolute values. */
> + ms_type = mst_abs;
> + sec = cs_to_section (cs, objfile);
> + tmpaddr = cs->c_value;
> + }
> else
> {
> sec = cs_to_section (cs, objfile);
> tmpaddr = cs->c_value;
> !
> ! /* Statics in a PE file also get relocated */
> ! if (cs->c_sclass == C_EXT
> ! || cs->c_sclass == C_THUMBEXTFUNC
> ! || cs->c_sclass == C_THUMBEXT
> ! || (pe_file && (cs->c_sclass == C_STAT)))
> tmpaddr += ANOFFSET (objfile->section_offsets, sec);
>
> if (sec == SECT_OFF_TEXT (objfile))
> 2003-02-26 Raoul Gough <RaoulGough@yahoo.co.uk>
>
> * coffread.c(coff_symtab_read): DO relocate static symbols from PE
> files, DON'T relocate absolute symbols (and DO use mst_abs).
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: RFC: coffread.c relocation fixes
2003-05-23 16:19 ` Elena Zannoni
@ 2003-05-28 15:04 ` Raoul Gough
2003-05-28 15:42 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Raoul Gough @ 2003-05-28 15:04 UTC (permalink / raw)
To: Elena Zannoni; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]
"Elena Zannoni" <ezannoni@redhat.com> wrote in message
news:16078.19295.731449.579816@localhost.redhat.com...
> Raoul Gough writes:
[snip]
> > I've added the script as a note to PR 1132 in GNATS (see
> > http://sources.redhat.com/ml/gdb-prs/2003-q2/msg00129.html).
> >
>
> I don't have much comments on the test (except that the convention
is
> to use '-' instead of '_' in file names, and that you need to update
> the gdb/config/djgpp/fnchange.lst file). I wonder if instead of
'while 1'
> you could use exp_continue. MichaelC?
Oh, DOS 8.3 filenames - I see... probably best to rename the files
everywhere - otherwise the shared-reloc.exp script would have to be
aware of the renaming issue on DJGPP (since it invokes the compiler on
the long-named .c files). I've attached the new versions to this post.
BTW, I think Andrew Cagney is sorting out CVS access for me, so I may
be able to add the test to CVS myself, if that's appropriate. I wonder
if this test works on DJGPP?
Regarding the "while 1" issue - my TCL/expect skills are so minimal, I
couldn't think of a better way of doing the loop - an improvement
would be good, as long as it doesn't involve me learning any more TCL
:-)
> > I've attached an updated diff to this posting with a fix for the
typo
> > that Elena identified. Any advice on getting these patches
checked in
> > and the PR closed? I can't do it myself, since I don't have any
write
> > access.
> >
>
> I can commit it for you.
Thanks for this - the latest CVS version now passes the shared object
relocation tests.
Regards,
Raoul Gough.
[-- Attachment #2: shreloc.c --]
[-- Type: text/plain, Size: 344 bytes --]
#if defined(_WIN32) || defined(__CYGWIN__)
# define ATTRIBUTES __attribute((__dllimport__))
#else
# define ATTRIBUTES
#endif
extern ATTRIBUTES void fn_1 (int);
extern ATTRIBUTES void fn_2 (int);
extern ATTRIBUTES int extern_var_1;
extern ATTRIBUTES int extern_var_2;
int main ()
{
fn_1 (extern_var_1);
fn_2 (extern_var_2);
return 0;
}
[-- Attachment #3: shreloc2.c --]
[-- Type: text/plain, Size: 223 bytes --]
#if defined(_WIN32) || defined(__CYGWIN__)
# define ATTRIBUTES __attribute((__dllexport__))
#else
# define ATTRIBUTES
#endif
static int static_var_2;
ATTRIBUTES void fn_2 (int unused) { }
ATTRIBUTES int extern_var_2 = 0;
[-- Attachment #4: shreloc1.c --]
[-- Type: text/plain, Size: 223 bytes --]
#if defined(_WIN32) || defined(__CYGWIN__)
# define ATTRIBUTES __attribute((__dllexport__))
#else
# define ATTRIBUTES
#endif
static int static_var_1;
ATTRIBUTES void fn_1 (int unused) { }
ATTRIBUTES int extern_var_1 = 0;
[-- Attachment #5: shreloc.exp --]
[-- Type: application/octet-stream, Size: 7161 bytes --]
# Copyright (C) 2003 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu
# Tests for shared object file relocation. If two shared objects have
# the same load address (actually, overlapping load spaces), one of
# them gets relocated at load-time. Check that gdb gets the right
# values for the debugging and minimal symbols.
if $tracelevel then {
strace $tracelevel
}
#
# This file uses shreloc.c, shreloc1.c and shreloc2.c
#
set prms_id 0
set bug_id 0
set workdir ${objdir}/${subdir}
foreach module [list "shreloc" "shreloc1" "shreloc2"] {
if {[gdb_compile "${srcdir}/${subdir}/${module}.c" "${workdir}/${module}.o" object {debug}] != ""} {
gdb_suppress_entire_file "${module}.c compile failed, so all tests in this file will automatically fail."
return -1
}
}
set additional_flags "additional_flags=-shared"
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
set additional_flags "${additional_flags} -Wl,--image-base,0x04000000"
}
foreach module [list "shreloc1" "shreloc2"] {
if {[gdb_compile "${workdir}/${module}.o" "${workdir}/${module}.dll" executable [list debug $additional_flags]] != ""} {
gdb_suppress_entire_file "${module}.dll link failed, so all tests in this file will automatically fail."
return -1
}
}
if {[gdb_compile [list "${workdir}/shreloc.o" "${workdir}/shreloc1.dll" "${workdir}/shreloc2.dll"] "${workdir}/shreloc" executable debug] != ""} {
gdb_suppress_entire_file "shreloc link failed, so all tests in this file will automatically fail."
return -1
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${workdir}/shreloc
# Load up the shared objects
if ![runto_main] then {
fail "Can't run to main"
return 0
}
proc get_var_address { var } {
global gdb_prompt hex
send_gdb "print &${var}\n"
# Match output like:
# $1 = (int *) 0x0
# $5 = (int (*)()) 0
# $6 = (int (*)()) 0x24 <function_bar>
gdb_expect {
-re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
{
pass "get address of ${var}"
if { $expect_out(1,string) == "0" } {
return "0x0"
} else {
return $expect_out(1,string)
}
}
-re "${gdb_prompt} $"
{ fail "get address of ${var} (unknown output)" }
timeout
{ fail "get address of ${var} (timeout)" }
}
return ""
}
#
# Check debugging symbol relocations
#
# Check extern function for relocation
set fn_1_addr [get_var_address fn_1]
set fn_2_addr [get_var_address fn_2]
if { "${fn_1_addr}" == "${fn_2_addr}" } {
fail "relocated extern functions have different addresses"
} else {
pass "relocated extern functions have different addresses"
}
# Check extern var for relocation
set extern_var_1_addr [get_var_address extern_var_1]
set extern_var_2_addr [get_var_address extern_var_2]
if { "${extern_var_1_addr}" == "${extern_var_2_addr}" } {
fail "relocated extern variables have different addresses"
} else {
pass "relocated extern variables have different addresses"
}
# Check static var for relocation
set static_var_1_addr [get_var_address static_var_1]
set static_var_2_addr [get_var_address static_var_2]
if { "${static_var_1_addr}" == "${static_var_2_addr}" } {
fail "relocated static variables have different addresses"
} else {
pass "relocated static variables have different addresses"
}
#
# Check minimal symbol relocations
#
proc send_gdb_discard { command } {
# Send a command to gdb and discard output up to the next prompt
global gdb_prompt
send_gdb "${command}\n"
# Discard output
gdb_expect {
-re ".*\[\r\n]+${gdb_prompt} $" {
return 1
}
timeout {
fail "{$command} (timeout)"
return 0
}
}
}
proc get_msym_addrs { var msymfile } {
# Extract the list of values for symbols matching var in the
# minimal symbol output file
global gdb_prompt hex
set result ""
send_gdb "shell grep -E \" ${var}(\[ \t\]+.*)?\$\" ${msymfile}\n"
while 1 {
gdb_expect {
-re "\[\[\]\[ 0-9\]+\] . (${hex}) ${var}(\[ \t\]+\[^\r\n\]*)?\[\r\n\]+" {
set result [concat $result $expect_out(1,string)]
}
-re "$gdb_prompt $" {
pass "get_msym_addrs ${var} (${result})"
return "${result}"
}
-re "\[^\r\n\]*\[\r\n\]+" {
# Skip
}
timeout {
fail "get_msym_addrs ${var} (timeout)"
return -1
}
}
}
}
proc check_same {var msymfile} {
# Check that the minimal symbol values matching var are the same
set len [llength [lsort -unique [get_msym_addrs "${var}" "${msymfile}"]]]
if { $len == 1 } {
return 1
} else {
return 0
}
}
proc check_different {var msymfile} {
# Check that the minimal symbol values matching var are different
set addr_list [lsort [get_msym_addrs "${var}" "${msymfile}"]]
set prev ""
if { [llength ${addr_list}] < 2 } {
return 0
}
foreach addr ${addr_list} {
if { ${prev} == ${addr} } {
return 0
}
set prev ${addr}
}
return 1
}
set msymfile "${workdir}/shreloc.txt"
if [send_gdb_discard "maint print msymbols ${msymfile}"] {
if {[check_different "static_var_\[12\]" "${msymfile}"]} {
pass "(msymbol) relocated static vars have different addresses"
} else {
fail "(msymbol) relocated static vars have different addresses"
}
if {[check_different "extern_var_\[12\]" "${msymfile}"]} {
pass "(msymbol) relocated extern vars have different addresses"
} else {
fail "(msymbol) relocated extern vars have different addresses"
}
if {[check_different "fn_\[12\]" "${msymfile}"]} {
pass "(msymbol) relocated functions have different addresses"
} else {
fail "(msymbol) relocated functions have different addresses"
}
}
if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
#
# We know the names of some absolute symbols included in the
# portable-executable (DLL) format. Check that they didn't get
# relocated.
#
# A better approach would be include absolute symbols via the assembler.
#
if {[check_same "_minor_os_version__" "${msymfile}"]} {
pass "Absolute symbols not relocated"
} else {
fail "Absolute symbols not relocated"
}
}
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: RFC: coffread.c relocation fixes
2003-05-28 15:04 ` Raoul Gough
@ 2003-05-28 15:42 ` Eli Zaretskii
0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2003-05-28 15:42 UTC (permalink / raw)
To: RaoulGough; +Cc: ezannoni, gdb-patches
> From: "Raoul Gough" <RaoulGough@yahoo.co.uk>
> Date: Wed, 28 May 2003 16:05:04 +0100
>
> Oh, DOS 8.3 filenames - I see... probably best to rename the files
> everywhere - otherwise the shared-reloc.exp script would have to be
> aware of the renaming issue on DJGPP (since it invokes the compiler on
> the long-named .c files). I've attached the new versions to this post.
> BTW, I think Andrew Cagney is sorting out CVS access for me, so I may
> be able to add the test to CVS myself, if that's appropriate. I wonder
> if this test works on DJGPP?
I'm not sure what test are we talking about, but if it's about a test
from the test suite, then DJGPP doesn't support the suite because
`expect' and Dejagnu was not ported to DJGPP.
HTH
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: RFC: coffread.c relocation fixes
@ 2003-05-23 18:42 Michael Elizabeth Chastain
0 siblings, 0 replies; 8+ messages in thread
From: Michael Elizabeth Chastain @ 2003-05-23 18:42 UTC (permalink / raw)
To: ezannoni, RaoulGough; +Cc: gdb-patches
> I don't have much comments on the test (except that the convention is
> to use '-' instead of '_' in file names, and that you need to update
> the gdb/config/djgpp/fnchange.lst file). I wonder if instead of 'while 1'
> you could use exp_continue. MichaelC?
Dunno.
(I am on hiatus again, in case anyone hasn't noticed. I will be
back eventually).
Michael C
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2003-05-28 15:42 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-26 18:40 RFC: coffread.c relocation fixes Raoul Gough
2003-04-03 21:48 ` Elena Zannoni
2003-04-07 11:54 ` Raoul Gough
2003-05-12 16:38 ` Raoul Gough
2003-05-23 16:19 ` Elena Zannoni
2003-05-28 15:04 ` Raoul Gough
2003-05-28 15:42 ` Eli Zaretskii
2003-05-23 18:42 Michael Elizabeth Chastain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox