git: efi/loader: Fix libstand.a order in LDADD
Aaron LI
aly at crater.dragonflybsd.org
Fri Oct 2 05:08:15 PDT 2026
commit 20f38538b54e6364c0eb7328de5da73d6ae25737
Author: Aaron LI <aly at aaronly.me>
Date: Fri Oct 2 10:22:13 2026 +0800
efi/loader: Fix libstand.a order in LDADD
When I tried to use `strtok()` in `boot/dloader`, the `stand/efi/loader`
would fail the linking with an obscure error:
```
cc -pipe -O1 -fno-stack-protector -fPIC -I/usr/src/stand/boot/efi/loader/../../../contrib/edk2/MdePkg/Include -I/usr/src/stand/boot/efi/loader/../../../contrib/edk2/MdePkg/Include/X64 -I/usr/src/stand/boot/efi/loader/../../../contrib/edk2/MdeModulePkg/Include -I/usr/src/stand/boot/efi/loader -I/usr/src/stand/boot/efi/loader/arch/x86_64 -I/usr/src/stand/boot/efi/loader/../include -I/usr/src/stand/boot/efi/loader/../../../../sys/contrib/dev/acpica/source/include -I/usr/src/stand/boot/efi/loader/../../../../sys -I/usr/src/stand/boot/efi/loader/../../pc32/libi386 -I/usr/src/stand/boot/efi/loader/../../dloader -I/usr/src/stand/boot/efi/loader/../../../lib -DNO_PCI -DEFI -I/usr/src/stand/boot/efi/loader/../../common -O -D_STANDALONE -ffreestanding -Wformat -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float -fshort-wchar -mno-red-zone -mno-aes -std=gnu11 -Wmissing-include-dirs -Wsystem-headers -Wall -Wformat-security -Winit-self -Wextra -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wold-style-definition -Wno-pointer-sign -Wno-maybe-uninitialized -Wno-unused-parameter -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-stringop-overflow -Wno-address-of-packed-member -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -Wno-unused-value -Wno-implicit-fallthrough -Wl,-znocombreloc -Wl,-T/usr/src/stand/boot/efi/loader/arch/x86_64/ldscript.x86_64 -Wl,-Bsymbolic -shared -nostdlib -o loader.sym autoload.o bootinfo.o conf.o copy.o devicename.o efi_main.o i386_module.o main.o self_reloc.o smbios.o vers.o amd64_tramp.o start.o framebuffer.o elf64_freebsd.o nullconsole.o comconsole.o bcache.o boot.o commands.o console.o devopen.o interp_backslash.o interp_parse.o ls.o misc.o module.o panic.o rel_open.o load_elf32.o load_elf32_obj.o reloc_elf32.o load_elf64.o load_elf64_obj.o reloc_elf64.o do_dloader.o /usr/obj/usr/src/world_x86_64/usr/src/stand/boot/efi/loader/../libefi/libefi.a /usr/obj/usr/src/world_x86_64/usr/src/stand/boot/efi/loader/../../../lib/libstand.a /usr/obj/usr/src/world_x86_64/usr/src/stand/boot/efi/loader/../../dloader/libdloader.a
/usr/obj/usr/src/ctools_x86_64_x86_64/usr/libexec/binutils234/elf/ld.bfd: .eh_frame_hdr refers to overlapping FDEs
/usr/obj/usr/src/ctools_x86_64_x86_64/usr/libexec/binutils234/elf/ld.bfd: final link failed: bad value
collect2: error: ld returned 1 exit status
```
Reproducing the failing link with `ld.bfd --no-eh-frame-hdr` and dumping
`.eh_frame` showed:
```
00000018 00000014 FDE cie=0 pc=0x6000..0x600e <- efi_autoload (autoload.o)
00000030 00000024 FDE cie=0 pc=0x6000..0x6020 <- PLT .eh_frame
00000058 00000050 FDE cie=0 pc=0x600e..0x63ab <- bi_copymodules (bootinfo.o)
```
The second FDE is the linker-generated `.plt` unwind record. Its CFI
bytes are byte-for-byte `elf_x86_64_eh_frame_lazy_plt` from
`contrib/binutils-2.34/bfd/elf64-x86-64.c`, and the map shows the PLT is
at `.text+0x21f00`. It should cover the PLT, but it was emitted at `0x6000`,
overlapping `efi_autoload`.
The root cause turned to be the wrong archive order in
`stand/boot/efi/loader/Makefile`:
```
LDADD= ${LIBEFI} ${LIBSTAND} ${LIBDLOADER}
```
When `libstand.a` is scanned, nothing has referenced `strtok` yet, so
`strtok.o` is not pulled. Then `libdloader.a` pulls in `cmds.o`, which
introduces an undefined `strtok`, and no later library defines it.
Because this is a `-shared` link, the linker accepts the undefined
symbol instead of failing, giving it a dynamic symbol and a PLT slot.
The Makefile actually has a rule to caught such undefined symbols, but
the link died first.
Fix the bug by correcting the archive order.
Assisted-by: DeepSeek-v4.1-flash (with Pi Coding Agent)
Summary of changes:
stand/boot/efi/loader/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/20f38538b54e6364c0eb7328de5da73d6ae25737
--
DragonFly BSD source repository
More information about the Commits
mailing list