This is the mail archive of the libc-help@sourceware.org mailing list for the glibc 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]

Re: C Start-Up shared vs static


On Fri, 4 Dec 2009, Carlos O'Donell wrote:

> On Fri, Dec 4, 2009 at 8:48 AM, Charles Coldwell
> <coldwell@frank.harvard.edu> wrote:
> > So it seems to me there is a problem with including
> >
> > glibc-ports-2.8/sysdeps/arm/elf/start.S
> >
> > in both the shared and static libraries but including
> >
> > glibc-2.8/csu/elf-init.c
> >
> > in only the static library. ?What is the correct thing to do in this
> > situation?
> 
> Current git head has ARM's start.S loading __libc_csu_init and
> __libc_csu_fini via GOT entries in the shared case.
> 
> This patch added the code to distinguish between shared and static
> cases and use the GOT for shared:
> http://sourceware.org/git/?p=glibc-ports.git;a=commitdiff;h=856cb7775f0dc086c62eb2610e6e5613926e0a99
> 
> You might be able to backport this and see if it fixes your issue.

Thanks for the reply.  The patch seems to do as you advertise.  After 
applying this patch, if I assemble glibc-ports-2.8/sysdeps/arm/elf/start.S 
thus

$ arm-none-linux-gcc -c -o /tmp/start.o ../ports/sysdeps/arm/elf/start.S -fPIC
$ arm-none-linux-objdump -x /tmp/start.o

[ ... ]

SYMBOL TABLE:
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .ARM.attributes	00000000 .ARM.attributes
00000000 g     F .text	00000000 _start
00000000         *UND*	00000000 __libc_csu_fini
00000000         *UND*	00000000 main
00000000         *UND*	00000000 __libc_csu_init
00000000         *UND*	00000000 __libc_start_main
00000000         *UND*	00000000 abort
00000000 g       .data	00000000 __data_start
00000000  w      .data	00000000 data_start


RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE 
00000028 R_ARM_PC24        __libc_start_main
0000002c R_ARM_PC24        abort
00000030 R_ARM_ABS32       __libc_csu_fini
00000034 R_ARM_ABS32       main
00000038 R_ARM_ABS32       __libc_csu_init

And then again with "-DSHARED"

$ arm-none-linux-gcc -c -o /tmp/start.o ../ports/sysdeps/arm/elf/start.S -fPIC -DSHARED
$ arm-none-linux-objdump -x /tmp/start.o

[ ... ]

SYMBOL TABLE:
00000000 l    d  .text	00000000 .text
00000000 l    d  .data	00000000 .data
00000000 l    d  .bss	00000000 .bss
00000000 l    d  .ARM.attributes	00000000 .ARM.attributes
00000000 g     F .text	00000000 _start
00000000         *UND*	00000000 __libc_start_main
00000000         *UND*	00000000 abort
00000000         *UND*	00000000 _GLOBAL_OFFSET_TABLE_
00000000         *UND*	00000000 __libc_csu_fini
00000000         *UND*	00000000 __libc_csu_init
00000000         *UND*	00000000 main
00000000 g       .data	00000000 __data_start
00000000  w      .data	00000000 data_start


RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE 
0000003c R_ARM_PLT32       __libc_start_main
00000040 R_ARM_PC24        abort
00000044 R_ARM_GOTPC       _GLOBAL_OFFSET_TABLE_
00000048 R_ARM_GOT32       __libc_csu_fini
0000004c R_ARM_GOT32       __libc_csu_init
00000050 R_ARM_GOT32       main

The relocations for __libc_csu_fini and __libc_csu_init have been moved 
from absolute 32-bit addresses to entries in the global offset table.  
However, I still get the same result when I try to compile an executable 
using the library:

/Volumes/cross/usr/lib/gcc/arm-none-linux/4.3.3/../../../../arm-none-linux/lib/crt1.o: In function `_start':
init.c:(.text+0x2c): undefined reference to `__libc_csu_fini'
init.c:(.text+0x34): undefined reference to `__libc_csu_init'

because regardless of whether the referenced symbols are absolute 
addresses or offsets in the GOT, they are still undefined.  I am assuming 
there is more to it than just the patch you linked ... am I also supposed 
to remove line 33 from glibc-2.8/csu/Makefile

static-only-routines = elf-init

so that elf-init.o will be included in both shared and static versions of 
libc?

Thanks again,

-- 
Charles M. Coldwell, W1CMC
"Turn on, log in, tune out"
Winchester, Massachusetts, New England (FN42kk)

GPG ID:  852E052F
GPG FPR: 77E5 2B51 4907 F08A 7E92  DE80 AFA9 9A8F 852E 052F

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