gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gcl-devel] BFD test program


From: Camm Maguire
Subject: Re: [Gcl-devel] BFD test program
Date: 24 Jul 2002 13:09:34 -0400

Greetings!

"Mike Thomas" <address@hidden> writes:

> This is a multi-part message in MIME format.
> 
> ------=_NextPart_000_08B4_01C22CB4.9B67ED10
> Content-Type: text/plain;
>       charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit
> 
> Hi Camm.
> 
> Things are desperate, so I have resorted to making a separate BFD test
> program which is attached.  Basically it reads the symbol table in a GCL
> executable and then tries to load and relocate a previously compiled object
> file.  It is based on "build_symbol_table_bfd()" and "fasload()".
> 
> I would appreciate it greatly if you could take the time to do the following
> on an i386 Linux box, letting me know what happens and also offereing any
> advice you may have:
> 
> 1. cd to the top of your GCL source tree, with a built "saved_gcl" in the
> unixport directory.
> 
> 2. cat > t.lsp
> (defun t (a b) (+ a b))
> 
> 3. ./unixport /saved_gcl
> 
> 4. (compile-file "t.lsp")
> 
> 5. (by)
> 
> 6. build the attached source file:
> 
>     gcc bfdtest.c -g -lbfd -liberty -o bfdtest
> 
> 7. and run the resulting executable, logging the output:
> 
>     ./bfdtest   ./unixport/saved_gcl   t.o >& run.log
> 
> 8. send me the resulting log.
> 
> The resulting output from my Win 2000 machine is below, for comparison and
> comment.  Any explanation of what this stuff is trying to achieve during the
> initialisation phase (vma setting etc) would also be appreciated!
> 

OK, Here it is.  Basically, what is going on is the loading of the
executable part of a .o file into a block of memory governed by a lisp
object.  The address references of any data elements in the .o files
then need to be reset to the addresses of the newly loaded code in the
lisp object.  The vma setting specifies the beginning address for each
section of the .o file within the lisp buffer.  More on this later if
you'd like.

=============================================================================
BUILDING EXECUTABLE SYMBOL TABLE (ARGV[1]) 

Allocating symbol table (30944 bytes)
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.1
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.1
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.1
Processed @@GLIBC_2.1
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.1
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.1
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.1
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
Processed @@GLIBC_2.0
CALCULATING CURRENT, MAX_ALIGN and ALLOCATING ) 

round_up: address = 0, n = 4, returning 0
Section .text: owner = 805cab8, output_offset = 0, output_section = 804b068 
(.text)
round_up: address = 108, n = 4, returning 108
Section .data: owner = 805cab8, output_offset = 0, output_section = 804b1c4 
(.data)
round_up: address = 112, n = 4, returning 112
Section .bss: owner = 805cab8, output_offset = 0, output_section = 804b320 
(.bss)
Section .note: owner = 805cab8, output_offset = 0, output_section = 804b068 
(.text)
Section .comment: owner = 805cab8, output_offset = 0, output_section = 804b068 
(.text)
ALLOCATED 112 bytes 

max_align = 4, current = 112, cfd_self  = 0, cfd_size  = 70, cfd_start = 804bbf0
round_up: address = 134527984, n = 4, returning 134527984
max_align = 4, current = 112, cfd_self  = 0, cfd_size  = 70, cfd_start = 804bbf0
SETTING VMA'S

round_up: address = 134527984, n = 4, returning 134527984
Section .text: owner = 805cab8, output_offset = 0, output_section = 804b068 
(.text), vma = 804bbf0, m = 804bc5c
round_up: address = 134528092, n = 4, returning 134528092
Section .data: owner = 805cab8, output_offset = 0, output_section = 804b1c4 
(.data), vma = 804bc5c, m = 804bc60
round_up: address = 134528096, n = 4, returning 134528096
Section .bss: owner = 805cab8, output_offset = 0, output_section = 804b320 
(.bss), vma = 804bc60, m = 804bc60


DOING SOMETHING WITH THE HASHED SYMBOLS

q[0]->name = t.c
q[1]->name = 
q[2]->name = 
q[3]->name = 
q[4]->name = gcc2_compiled.
q[5]->name = VVi
q[6]->name = L1
q[7]->name = 
q[8]->name = 
q[9]->name = vs_base
q[10]->name = vs_limit
q[11]->name = vs_top
q[12]->name = vs_overflow
q[13]->name = number_plus
q[14]->name = init_code
q[15]->name = do_init


DOING RELOCATIONSs->name .text, s->flags = 237
About to get reloc section contents
b = 805cab8, section .text, s->output_section = 804b068, q = 804bc68
s->name .data, s->flags = 247
About to get reloc section contents
b = 805cab8, section .data, s->output_section = 804b1c4, q = 804bc68
s->name .bss, s->flags = 1
s->name .note, s->flags = 210
s->name .comment, s->flags = 210
=============================================================================


> Cheers
> 
> Mike Thomas.
> 
> ================================================
> $ ./bfdtest.exe ./unixport/saved_gcl.exe tg.o
> BUILDING EXECUTABLE SYMBOL TABLE (ARGV[1])
> 
> Allocating symbol table (38572 bytes)
> CALCULATING CURRENT, MAX_ALIGN and ALLOCATING )
> 
> round_up: address = 0, n = 4, returning 0
> Section .text: owner = 3f2438, output_offset = 0, output_section = 3faffc
> (.text
> )
> round_up: address = 136, n = 4, returning 136
> Section .data: owner = 3f2438, output_offset = 0, output_section = 3fb094
> (.data
> )
> round_up: address = 140, n = 4, returning 140
> Section .bss: owner = 3f2438, output_offset = 0, output_section = 3fb12c
> (.bss)
> ALLOCATED 140 bytes
> 
> max_align = 4, current = 140, cfd_self  = 0, cfd_size  = 8c, cfd_start =
> 56ff00
> round_up: address = 5701376, n = 4, returning 5701376
> max_align = 4, current = 140, cfd_self  = 0, cfd_size  = 8c, cfd_start =
> 56ff00
> SETTING VMA'S
> 
> round_up: address = 5701376, n = 4, returning 5701376
> Section .text: owner = 3f2438, output_offset = 0, output_section = 3faffc
> (.text
> ), vma = 56ff00, m = 56ff88
> round_up: address = 5701512, n = 4, returning 5701512
> Section .data: owner = 3f2438, output_offset = 0, output_section = 3fb094
> (.data
> ), vma = 56ff88, m = 56ff8c
> round_up: address = 5701516, n = 4, returning 5701516
> Section .bss: owner = 3f2438, output_offset = 0, output_section = 3fb12c
> (.bss),
>  vma = 56ff8c, m = 56ff8c
> 
> 
> DOING SOMETHING WITH THE HASHED SYMBOLS
> 
> q[0]->name = t.c
> q[1]->name = gcc2_compiled.
> q[2]->name = ___gnu_compiled_c
> q[3]->name = _VVi
> q[4]->name = _init_code
> q[5]->name = _L1
> q[6]->name = .text
> q[7]->name = .data
> q[8]->name = .bss
> q[9]->name = _vs_base
> q[10]->name = _vs_top
> q[11]->name = _vs_limit
> q[12]->name = _number_plus
> q[13]->name = _vs_overflow
> q[14]->name = _do_init
> 
> 
> DOING RELOCATIONSs->name .text, s->flags = 237
> About to get reloc section contents
> b = 3f2438, section .text, s->output_section = 3faffc, q = 3f2918
> 
> (HERE IT FALLS OVER AS PREVIOUSLY REPORTED IN
> "bfd_get_relocated_section_contents()" )
> 
> ------=_NextPart_000_08B4_01C22CB4.9B67ED10
> Content-Type: application/octet-stream;
>       name="bfdtest.c"
> Content-Transfer-Encoding: quoted-printable
> Content-Disposition: attachment;
>       filename="bfdtest.c"
> 
> #include <bfd.h>=0A=
> #include <bfdlink.h>=0A=
> #include <stdio.h>=0A=
> =0A=
> bfd *gclb;=0A=
> struct bfd_link_info link_info;=0A=
> =0A=
> static boolean=0A=
>     madd_archive_element (struct bfd_link_info * link_info,=0A=
>                            bfd *abfd,=0A=
>                            const char *name) {=0A=
> =0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     mmultiple_definition (struct bfd_link_info * link_info,=0A=
>                            const char *name,=0A=
>                            bfd *obfd,=0A=
>                            asection *osec,=0A=
>                            bfd_vma oval,=0A=
>                            bfd *nbfd,=0A=
>                            asection *nsec,=0A=
>                            bfd_vma nval) {=0A=
> =0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     mmultiple_common (struct bfd_link_info * link_info,=0A=
>                        const char *name,=0A=
>                        bfd *obfd,=0A=
>                        enum bfd_link_hash_type otype,=0A=
>                        bfd_vma osize,=0A=
>                        bfd *nbfd,=0A=
>                        enum bfd_link_hash_type ntype,=0A=
>                        bfd_vma nsize) {=0A=
> =0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     madd_to_set (struct bfd_link_info * link_info,=0A=
>                   struct bfd_link_hash_entry *entry,=0A=
>                   bfd_reloc_code_real_type reloc,=0A=
>                   bfd *abfd, asection *sec, bfd_vma value) {=0A=
> =0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static  boolean =0A=
>     mconstructor (struct bfd_link_info * link_info,boolean constructor,=0A=
>                    const char *name, bfd *abfd, asection *sec,=0A=
>                    bfd_vma value) {=0A=
> =0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     mwarning (struct bfd_link_info * link_info,=0A=
>                const char *warning, const char *symbol,=0A=
>                bfd *abfd, asection *section,=0A=
>                bfd_vma address) {=0A=
> =0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     mundefined_symbol (struct bfd_link_info * link_info,=0A=
>                         const char *name, bfd *abfd,=0A=
>                         asection *section,=0A=
>                         bfd_vma address,=0A=
>                         boolean fatal) {=0A=
> =0A=
>         fprintf(stderr, "%s is undefined\n",name);=0A=
>         return false;=0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     mreloc_overflow (struct bfd_link_info * link_info,=0A=
>                       const char *name,=0A=
>                       const char *reloc_name, bfd_vma addend,=0A=
>                       bfd *abfd, asection *section,=0A=
>                       bfd_vma address) {=0A=
> =0A=
>         fprintf( stderr, "reloc for %s is overflowing\n",name);=0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     mreloc_dangerous (struct bfd_link_info * link_info,=0A=
>                        const char *message,=0A=
>                        bfd *abfd, asection *section,=0A=
>                        bfd_vma address) {=0A=
> =0A=
>         fprintf( stderr, "reloc is dangerous %s\n",message);=0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     munattached_reloc (struct bfd_link_info * link_info,=0A=
>                         const char *name,=0A=
>                         bfd *abfd, asection *section,=0A=
>                         bfd_vma address) {=0A=
> =0A=
>         fprintf(stderr, "%s is unattached\n",name);=0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> static boolean=0A=
>     mnotice (struct bfd_link_info * link_info, const char *name,=0A=
>               bfd *abfd, asection *section, bfd_vma address) {=0A=
> =0A=
>         return false;=0A=
> =0A=
>     }=0A=
> =0A=
> /* align for power of two n */=0A=
> static void *=0A=
>     round_up ( void *address, unsigned int n )=0A=
> {=0A=
>     void *rv =3D (void *) ( ((unsigned int ) (address + n -1)) & ~(n-1) =
> );=0A=
>     fprintf ( stderr, "round_up: address =3D %d, n =3D %d, returning =
> %d\n",=0A=
>               address, n, rv );=0A=
>     return (rv) ;=0A=
> }=0A=
> =0A=
> #define ROUND_UP(a,b) round_up(a,b) =0A=
> =0A=
> int main(int argc, char **argv)=0A=
> {=0A=
> =0A=
>     bfd *b;=0A=
> =0A=
>     unsigned u, v;=0A=
> =0A=
>     asymbol **q;=0A=
>     asection *s;=0A=
> =0A=
>     struct bfd_link_callbacks link_callbacks;=0A=
>     struct bfd_link_order link_order;=0A=
> =0A=
>     int max_align =3D 0;=0A=
> =0A=
>     void *current =3D NULL;=0A=
>     void *cfd_self      =3D NULL;=0A=
>     void *cfd_start     =3D NULL;=0A=
>     int   cfd_size      =3D 0;=0A=
>     void *the_start     =3D NULL;=0A=
>     void *start_address =3D NULL;=0A=
>     void *m             =3D NULL;=0A=
>     =0A=
>     if ( argc < 3 ) {=0A=
>         fprintf ( stderr, "Need an object file argument for input\n" );=0A=
>     } else {=0A=
> =0A=
>         memset ( &link_info, 0, sizeof (link_info) );=0A=
>         memset ( &link_order, 0, sizeof (link_order) );=0A=
>         memset ( &link_callbacks, 0, sizeof (link_callbacks) );=0A=
>         =0A=
>         fprintf ( stderr, "BUILDING EXECUTABLE SYMBOL TABLE (ARGV[1]) =
> \n\n" );=0A=
>         build_symbol_table_bfd ( argv[1] );        =0A=
> =0A=
>         link_callbacks.add_archive_element =3D madd_archive_element;=0A=
>         link_callbacks.multiple_definition =3D mmultiple_definition;=0A=
>         link_callbacks.multiple_common     =3D mmultiple_common;=0A=
>         link_callbacks.add_to_set          =3D madd_to_set;=0A=
>         link_callbacks.constructor         =3D mconstructor;=0A=
>         link_callbacks.warning             =3D mwarning;=0A=
>         link_callbacks.undefined_symbol    =3D mundefined_symbol;=0A=
>         link_callbacks.reloc_overflow      =3D mreloc_overflow;=0A=
>         link_callbacks.reloc_dangerous     =3D mreloc_dangerous;=0A=
>         link_callbacks.unattached_reloc    =3D munattached_reloc;=0A=
>         link_callbacks.notice              =3D mnotice;=0A=
> =0A=
>         if ( ! ( b =3D bfd_openr ( argv[2], 0 ) ) ) {=0A=
>             fprintf ( stderr, "Cannot open bfd");=0A=
>         }=0A=
>         =0A=
>         if ( ! bfd_check_format ( b, bfd_object ) ) {=0A=
>             fprintf ( stderr, "Unknown bfd format");=0A=
>         }=0A=
> =0A=
>         /*link_info.hash =3D bfd_link_hash_table_create (b);*/=0A=
>         link_info.callbacks=3D&link_callbacks;=0A=
> =0A=
>         link_order.type=3Dbfd_indirect_link_order;=0A=
> =0A=
>         current=3D0;=0A=
> =0A=
>         fprintf ( stderr, "CALCULATING CURRENT, MAX_ALIGN and ALLOCATING =
> ) \n\n" );=0A=
>         for ( s =3D b->sections; s ; s=3Ds->next ) {=0A=
>             s->owner          =3D b;=0A=
>             s->output_offset  =3D 0;=0A=
> =0A=
>             if (s->flags & SEC_ALLOC) {=0A=
>                 if ( max_align < s->alignment_power ) {=0A=
>                     max_align=3Ds->alignment_power;=0A=
>                 }=0A=
>                 current =3D round_up ( current, 1 << s->alignment_power =
> );=0A=
>                 current +=3D s->_raw_size;=0A=
>                 s->output_section =3D s;=0A=
>             } else {=0A=
>                 s->output_section =3D b->sections;=0A=
>             }=0A=
>             fprintf ( stderr, "Section %s: owner =3D %x, output_offset =
> =3D %x, output_section =3D %x (%s)\n",=0A=
>                       s->name, s->owner, s->output_offset, =
> s->output_section, s->output_section->name );=0A=
>         }=0A=
> =0A=
>         max_align =3D 1 << max_align;=0A=
>         cfd_self  =3D 0;=0A=
>         cfd_size  =3D current + (max_align > sizeof(char *) ? max_align =
> :0);=0A=
>         the_start =3D start_address =3D cfd_start =3D malloc ( cfd_size =
> );=0A=
> =0A=
>         fprintf ( stderr, "ALLOCATED %d bytes \n\n", cfd_size );=0A=
>         fprintf ( stderr,=0A=
>                   "max_align =3D %d, current =3D %d, cfd_self  =3D %x, "=0A=
>                   "cfd_size  =3D %x, cfd_start =3D %x\n",=0A=
>                   max_align, current, cfd_self, cfd_size, cfd_start );=0A=
> =0A=
>         start_address =3D ROUND_UP ( start_address, max_align );=0A=
>         cfd_size      =3D cfd_size - (start_address - the_start);=0A=
>         cfd_start     =3D (void *) start_address;=0A=
> =0A=
>         fprintf ( stderr,=0A=
>                   "max_align =3D %d, current =3D %d, cfd_self  =3D %x, "=0A=
>                   "cfd_size  =3D %x, cfd_start =3D %x\n",=0A=
>                   max_align, current, cfd_self, cfd_size, cfd_start );=0A=
> =0A=
> =0A=
>         memset ( cfd_start, 0, cfd_size );=0A=
> =0A=
>         fprintf ( stderr, "SETTING VMA'S\n\n" );=0A=
>         for ( m =3D start_address, s =3D b->sections; s; s =3D s->next ) =
> {=0A=
> =0A=
>             if ( s->flags & SEC_ALLOC ) {=0A=
>                 m =3D round_up ( m, 1 << s->alignment_power );=0A=
>                 s->output_section->vma =3D (bfd_vma) m;=0A=
>                 m +=3D s->_raw_size;=0A=
>                 fprintf ( stderr, "Section %s: owner =3D %x, =
> output_offset =3D %x, "=0A=
>                           "output_section =3D %x (%s), vma =3D %x, m =3D =
> %x\n",=0A=
>                           s->name, s->owner, s->output_offset, =
> s->output_section, s->output_section->name,=0A=
>                           s->output_section->vma, m );=0A=
>             }=0A=
>             =0A=
>         }=0A=
> =0A=
>         fprintf ( stderr, "\n\nDOING SOMETHING WITH THE HASHED =
> SYMBOLS\n\n" );=0A=
>         if ( ( u =3D bfd_get_symtab_upper_bound ( b ) ) < 0 ) {=0A=
>             fprintf ( stderr, "Cannot get symtab upper bound");=0A=
>         }=0A=
> =0A=
>         q =3D (asymbol **) malloc ( u );=0A=
>         =0A=
>         if ( ( v =3D bfd_canonicalize_symtab ( b, q ) ) < 0 ) {=0A=
>             fprintf ( stderr, "cannot canonicalize symtab");=0A=
>         }=0A=
> =0A=
>         for ( u=3D0; u<v; u++ ) {=0A=
> =0A=
>             struct bfd_link_hash_entry *h;=0A=
> =0A=
>             fprintf ( stderr, "q[%d]->name =3D %s\n", u, q[u]->name );=0A=
>             =0A=
>             if ( h =3D bfd_link_hash_lookup ( link_info.hash, =
> q[u]->name, false, false, true ) ) {=0A=
> =0A=
>                 if ( h->type !=3D bfd_link_hash_defined ) {=0A=
>                     fprintf ( stderr, "Undefined symbol");=0A=
>                 }=0A=
>                 if ( h->u.def.section ) {=0A=
>                     q[u]->value =3D h->u.def.value + =
> h->u.def.section->vma;=0A=
>                     q[u]->flags |=3D BSF_WEAK;=0A=
>                 } else  {=0A=
>                     fprintf ( stderr, "Symbol without section");=0A=
>                 }=0A=
>             }=0A=
>         }=0A=
> =0A=
>         fprintf ( stderr, "\n\nDOING RELOCATIONS", cfd_size );=0A=
>         for ( s =3D b->sections; s; s =3D s->next ) {=0A=
>             =0A=
>             fprintf ( stderr, "s->name %s, s->flags =3D %x\n", s->name, =
> s->flags );=0A=
> =0A=
>             if ( s->flags & SEC_LOAD ) {=0A=
>                 =0A=
>                 link_order.u.indirect.section =3D s;=0A=
> =0A=
>                 fprintf ( stderr, "About to get reloc section =
> contents\n" );=0A=
> =0A=
>                 fprintf ( stderr, "b =3D %x, section %s, =
> s->output_section =3D %x, q =3D %x\n",=0A=
>                           b, s->name, s->output_section, q);=0A=
>                 if ( ! bfd_get_relocated_section_contents (b, =
> &link_info, &link_order,=0A=
>                                                             (void *) =
> s->output_section->vma, 0, q ) ) {=0A=
>                     fprintf ( stderr, "Cannot get relocated section =
> contents\n");=0A=
>                 }=0A=
>             }=0A=
>         }=0A=
> =0A=
>         free (q);=0A=
>         bfd_close(b);=0A=
>         exit (0);=0A=
> #ifndef USE_T_O        =0A=
>     }=0A=
> #endif    =0A=
> }=0A=
> =0A=
> int build_symbol_table_bfd ( char *oname ) {=0A=
> =0A=
>     int u, v;=0A=
>     asymbol **q;=0A=
> =0A=
>     bfd_init();=0A=
> =0A=
>     if ( ! ( gclb =3D bfd_openr ( oname, 0 ) ) ) {=0A=
>         fprintf ( stderr,"Cannot open self\n");=0A=
>     }=0A=
>     =0A=
>     if ( ! bfd_check_format ( gclb, bfd_object ) ) {=0A=
>         fprintf ( stderr,"I'm not an object");=0A=
>     }=0A=
>     =0A=
>     /*    if (link_info.hash) */=0A=
>     /*      bfd_link_hash_table_free(gclb,link_info.hash); */=0A=
> =0A=
>     if ( ! (link_info.hash =3D bfd_link_hash_table_create (gclb) ) ) {=0A=
>         fprintf ( stderr,"Cannot make hash table");=0A=
>     }=0A=
> =0A=
>     if ( ! bfd_link_add_symbols ( gclb, &link_info ) ) {=0A=
>         fprintf ( stderr,"Cannot add self symbols\n");=0A=
>     }=0A=
>     if ( ( u =3D bfd_get_symtab_upper_bound ( gclb ) ) < 0 ) {=0A=
>         fprintf ( stderr,"Cannot get self's symtab upper bound");=0A=
>     }=0A=
> =0A=
>     fprintf ( stderr, "Allocating symbol table (%d bytes)\n", u );=0A=
>     q=3D(asymbol **)malloc(u);=0A=
> =0A=
>     if ( ( v =3D bfd_canonicalize_symtab ( gclb, q ) ) < 0 ) {=0A=
>         fprintf ( stderr,"Cannot canonicalize self's symtab");=0A=
>     }=0A=
> =0A=
>     for ( u =3D 0; u < v; u++ ) {=0A=
>         char *c;=0A=
>         /*fprintf ( stderr,=0A=
>                   "object file %s: q[%d] =3D %s, flag =3D %x\n",=0A=
>                   oname, u, q[u]->name, (char *) strstr (q[u]->name, =
> "@@GLIBC" ) );*/=0A=
>         =0A=
>         if ( ( c =3D (char *) strstr (q[u]->name, "@@GLIBC" ) ) ) {=0A=
>             struct bfd_link_hash_entry *h;=0A=
>             *c=3D0;=0A=
>             if ( ! (h =3D bfd_link_hash_lookup (link_info.hash, =
> q[u]->name, true, true, true ) ) ) {=0A=
>                 fprintf ( stderr,"Cannot make new hash entry");=0A=
>             }=0A=
>             h->type =3D bfd_link_hash_defined;=0A=
>             if ( !q[u]->section ) {=0A=
>                 fprintf ( stderr, "Symbol is missing section");=0A=
>             }=0A=
>             h->u.def.value   =3D q[u]->value + q[u]->section->vma;=0A=
>             h->u.def.section =3D q[u]->section;=0A=
>             *c=3D'@';=0A=
>             fprintf ( stderr, "Processed %s\n", c );=0A=
>         }=0A=
>     }=0A=
>     free ( q );=0A=
>     bfd_close ( gclb );=0A=
>     return 0;=0A=
>     =0A=
> }=0A=
> 
> ------=_NextPart_000_08B4_01C22CB4.9B67ED10--
> 
> 
> _______________________________________________
> Gcl-devel mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/gcl-devel
> 
> 

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah



reply via email to

[Prev in Thread] Current Thread [Next in Thread]