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]

How to resolve forward reference symbols (both within same and different object modules) in bfd/gas/linker


Hi,
  I am working on developing a cross assembler(gas) and linker for a
new target in gnu tool chain.
During this experimentation, I am facing couple of problems with
respect to forward reference symbols.
Problem i - New cross linker complaining undefined references even
when the global/static variable
                is declared and defined in same source file.
Detailed summary:
               In optimized mode (O >=1) gcc compiler emits the data section at
            the end of the assembly file, and all the global/static
symbols referring
            to this .data section becomes undefined at assembler(gas)
level and linker level.
            In non-optimized mode, gcc emits data section at top of
assembly file, so all
            global/static symbols referring to .data gets resolved
            Steps to reproduce the problem:
            1) Have a simple testcase with a static and global variable
            2) ./xgcc.exe -S -O1 test_pgm.c
            3) $GAS/as-new.exe test_pgm.s -o test_pgm.o
            4) $LD/ld-new.exe test_pgm.o
                    ==> Reports undefined references for all global
and static symbols
                        if program was compiled with optimization_level >= 1
            My understanding is that if a global/static variable is
declared and defined
            in the same source file, the linker should be able to
resolve by itself.
            Am I missing something here?

Problem ii - New cross-linker complains undefined references when the
global/static variable
             is declared in one source file and defined some other source file.
           Steps to reproduce the problem:
            1) Have two testcases(test1.c, test2.c) with a global
variable defined in test2.c and declared in test1.c
            2) ./xgcc.exe -S -O1 test1.c test2.c
            3) $GAS/as-new.exe test1.s -o test1.o
            4) $GAS/as-new.exe test2.s -o test2.o
            5) $LD/ld-new.exe test1.o test2.o
                    ==> Reports undefined references where global
variables are referenced but not defined.

I also experimented with various other cross compilers that includes
ppc-elf, arm-elf,
avr-elf, mips-elf along with its respective binutils and I found that
problem i and ii appears there as well.
Please let me know if I am missing something here. Any help to
identify the problem would be highly appreciated.

gcc -v output for a sample mips-elf
-----------------------------------
$GCC/gcc-mips/gcc $ ./xgcc.exe -v
Using built-in specs.
Target: mips-elf
Configured with: ../gcc/gccSrc/configure --enable-debug=full
--prefix=$HOME/mips --target=mips-elf --enable-checking
--disable-shared --disable-threads --without-headers --with-newlib
--enable-languages=c --with-gnu-ld --with-gnu-as
Thread model: single
gcc version 4.1.2
gas -v output
--------------
 $ ./as-new.exe -v
GNU assembler version 2.19.1 (mips-elf) using BFD version (GNU Binutils) 2.19.1


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