Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use mold for linking whole FreeBSD base and kernel - stuck at i386 BTX linking... #1209

Open
freebsd-nils-level1 opened this issue Feb 29, 2024 · 0 comments

Comments

@freebsd-nils-level1
Copy link

Hi,

in order to try out mold for linking all of FreeBSD base and kernel, I've patched the source code of mold:
elf/cmdline.cc: } else if (arg == "elf_i386" || arg == "elf_i386_fbsd") {
to recognize FreeBSD's "elf_i386_fbsd" target emulation as standard "elf_i386".

So far linking works well with some tuning of FreeBSD's make files, but now I am stuck at linking the i386 BTX located at FreeBSD's /usr/src/stand/i386/btx/btx. It builds a DOS executable (COM), so no ELF at all. And it uses a linker script:

/* Simplified linker script for the boot loaders. */

OUTPUT_FORMAT("elf32-i386-freebsd")
OUTPUT_ARCH(i386)
ENTRY(_start)
SECTIONS {
  . = ORG;
  .text : { *(.text .text.*) } =0xcccccccc      /* Pad with int3, if needed */
  .rodata : { *(.rodata .rodata.*) }
  .got : { *(.got) *(.igot) }
  .got.plt : { *(.got.plt) *(.igot.plt) }
  .data : { *(.data .data.*) }
  _edata = .; PROVIDE (edata = .);
  .bss : { *(.bss .bss.*) }
  _end = .; PROVIDE (end = .);
  /DISCARD/ : { *(.interp) }
}

I've tried to recreate that using "--section-order" args to mold, but:

"/usr/local/bin/mold" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -m elf_i386_fbsd -o btx.full -L/usr/lib32 --compress-debug-sections=zlib -e start --oformat=binary "--section-order==0x9000 .text .got .got.plt .data edata .bss .end" -N -S --build-id=none -zrelro --no-rosegment btx.o
mold: error: --section-order: missing section specification for .rel.dyn
mold: error: --section-order: missing section specification for .rel.plt
mold: error: --section-order: missing section specification for .plt
mold: error: --section-order: missing section specification for .plt.got
mold: error: --section-order: missing section specification for .dynsym
mold: error: --section-order: missing section specification for .dynstr
mold: error: --section-order: missing section specification for .eh_frame
mold: error: --section-order: missing section specification for .copyrel
mold: error: --section-order: missing section specification for .copyrel.rel.ro
mold: error: --section-order: missing section specification for .interp
mold: error: --section-order: missing section specification for .eh_frame_hdr
mold: error: --section-order: missing section specification for .hash
mold: error: --section-order: missing section specification for .gnu.hash
mold: error: --section-order: missing section specification for .gnu.version
mold: error: --section-order: missing section specification for .gnu.version_r
mold: error: --section-order: missing section specification for .note.package
mold: error: --section-order: missing section specification for .note.gnu.property

The original ld cmdline is:

 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags \
-m elf_i386_fbsd -o btx -L/usr/lib32 \
-e start --defsym ORG=0x9000 -T /usr/src/stand/i386/boot.ldscript \
-N -S --oformat binary --build-id=none -zrelro --no-rosegment btx.o

vs mold cmdline:

 "/usr/local/bin/mold" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags \
-m elf_i386_fbsd -o btx.full -L/usr/lib32 \
--compress-debug-sections=zlib -e start --oformat=binary "--section-order==0x9000 .text .got .got.plt .data edata .bss .end" \
-N -S --build-id=none -zrelro --no-rosegment btx.o

Now I am stuck. Any help is very appreciated...

TIA and BR,
Nils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant