This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: Compile and build tests with too many sections.


On Fri, Jan 22, 2016 at 06:54:52PM +0000, Shankar Easwaran wrote:
> I have a test which generates too many sections and we expect the linker to   
> resolve a COMMON symbol that exists in  multiple files.
> 
> Test :-
> 
> cat > gen.py << \!
> for i in range (0, 90000):
>     print "int foo%d() { return 0; }" % (i)
> print "int mycommon[10];"
> !
> 
> cat > gen2.py << \!
> for i in range (0, 90000):
>     print "int bar%d() { return 0; }" % (i)
> print "int mycommon[20];"
> !
> 
> python gen.py > gen.c
> python gen2.py > gen2.c
> 
> g++ -c -ffunction-sections gen.c
> g++ -c -ffunction-sections gen2.c
> ld gen.o gen2.o
> gen2.o:(.bss+0x0): multiple definition of `mycommon'
> gen.o:(.bss+0x0): first defined here
> 
> Further analyzing the problem, it looks like ths symbol mycommon gets 
> allocated in the section .bss as opposed to being a COMMON symbol.

Well, yes, you did compile using g++ after all.  C++ is not C, and one
of the differences is how uninitialized global variables behave.

> Digging into the object file, When I see the generated file, the reserved 
> section index SHN_COMMON gets used  up in the object file for symbols 
> outside COMMON symbols.

You might need to look a little deeper into the object than readelf
shows you.  You'll find that symbols defined in sections with indices
of 0xff00 and higher use SHN_XINDEX in ".symtab".  The actual index
for these symbols is found in ".symtab_shndx".

-- 
Alan Modra
Australia Development Lab, IBM


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