Skip to content
Advertisement

Linker –whole-archive option

I am using C language.

I am linking static libraries with --whole-archive. Linker is arm-none-eabi-ld

For example, giving the following option to the linker:

--whole-archive abc.a def.a

But still I get linking error:

(.text.boot+0x94): undefined reference to `xyz'
...

Why is the linking error happening?

EDIT:

Full command with output:

make[1]: Entering directory '/home/Project1/kern'
arm-none-eabi-ld -o /home/Project1/kernel.elf -T memmap.ld  
     hal/arm/arm_startup.o --whole-archive kunit.a hal.a fs.a --no-whole-archive /home/Project1/lib/lpc.a
hal/arm/arm_startup.o: In function `start':
(.text.boot+0x94): undefined reference to `mmu_init'
hal/arm/arm_startup.o: In function `halt':
(.text.boot+0x98): undefined reference to `exec_array'
hal.a(arm_int_handlers.o): In function `interrupt_svc':
(.text+0x18): undefined reference to `mmu_pagetable'
hal.a(arm_int_handlers.o): In function `interrupt_svc':
(.text+0x5c): undefined reference to `_enter_kernel'
...

Out put of:

readelf -Ws kunit.a hal.a fs.a | egrep ' (mmu_init|exec_array|mmu_pagetable|_enter_kernel)'

is:

     9: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND mmu_pagetable
    10: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND _enter_kernel
    12: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND mmu_pagetable

Advertisement

Answer

Why is the linking error happening?

Because the symbols that you are missing: mmu_init, mmu_pagetable, etc. are in fact not defined in the libraries you expected them to be defined in.

That’s what UND in readelf output means.

Now, in order to tell you why these symbols are not defined, we’d need to know the origin of the libraries you expected them to be defined in, how these libraries were built, and possibly a lot of other details. Please ask a separate question with all the details that you can think of.

Advertisement