Page MenuHomeFreeBSD

Move to linker script for building boot images
ClosedPublic

Authored by imp on Aug 3 2016, 5:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 16 2022, 1:17 AM
Unknown Object (File)
Dec 15 2022, 12:13 AM
Unknown Object (File)
Dec 15 2022, 12:10 AM
Unknown Object (File)
Dec 15 2022, 12:07 AM
Unknown Object (File)
Dec 14 2022, 11:58 PM
Unknown Object (File)
Apr 15 2017, 6:12 PM
Unknown Object (File)
Feb 16 2017, 1:19 AM
Unknown Object (File)
Jan 19 2017, 5:21 AM
Subscribers
None

Details

Summary

Move to using a linker script in preference to -N when building binary blobs we put places.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

imp retitled this revision from to Move to linker script for building boot images.
imp updated this object.
imp edited the test plan for this revision. (Show Details)
imp added a reviewer: emaste.
imp set the repository for this revision to rS FreeBSD src repository - subversion.
sys/boot/i386/boot.ldscript
2–4 ↗(On Diff #19011)

It isn't clear these three lines are needed. will test w/o them.

6 ↗(On Diff #19011)

Not sure we have to set the origin.

7 ↗(On Diff #19011)

Not sure I need the =0x90909090 here either.
What does it even do?

sys/boot/i386/Makefile.inc
33–34 ↗(On Diff #19011)

Perhaps these two could have a comment explaining their use (i.e., flat binaries vs ELF output)?

sys/boot/pc98/boot0/Makefile
17 ↗(On Diff #19011)

Oh, so we previously wrote an intermediate ELF file for just this one case and then converted it to a flat binary, but all others were output by ld directly as binaries?

sys/boot/i386/Makefile.inc
33–34 ↗(On Diff #19011)

Isn't that what line 31 does?

sys/boot/pc98/boot0/Makefile
17 ↗(On Diff #19011)

Correct. Up through https://svnweb.freebsd.org/base?view=revision&revision=128649 i386 did the same. Obrien never got around to this stray, and nyan-san never merged it either.

Note we also use -N in some mips, sparc64, and powerpc boot components. I think it's reasonable to leave them for a subsequent change.

sys/boot/i386/boot.ldscript
7 ↗(On Diff #19011)

That's the value ld will use for padding - NOP NOP NOP NOP here. To me it seems like 0xcccccccc might be better (four INT3s) since we don't expect to execute random padding bytes between blocks of .text. But this is canonical and consistent with the rest of the system so I would leave it as is.

sys/boot/i386/Makefile.inc
33–34 ↗(On Diff #19011)

I mean the use of LDFLAGS_BIN vs LD_FLAGS_BIN -- possibly ELF objects vs flat binaries? The line 31 comment applies mostly to the linker script itself IMO?

sys/boot/i386/Makefile.inc
33–34 ↗(On Diff #19011)

LD_FLAGS vs LDFLAGS is a build system thing. LDFLAGS is used for $CC invocations while LD_FLAGS is used for direct $LD invocations.

sys/boot/i386/Makefile.inc
33–34 ↗(On Diff #19011)

Right, but these are also producing different output format etc.
It looks like we're using the compiler driver invocation to produce flat binaries, and direct ld invocation to produce ELF objects.

sys/boot/i386/Makefile.inc
33–34 ↗(On Diff #19011)

Oh, but it seems the direct ld invocations also use ${OBJCOPY} to convirt to a flat binary like pc98/boot0 used to anyhow.

Note we also use -N in some mips, sparc64, and powerpc boot components. I think it's reasonable to leave them for a subsequent change.

Does this militate to moving the boot.ldscript up to sys/boot and have it be called ldscript.$MACHINE?

Does this militate to moving the boot.ldscript up to sys/boot and have it be called ldscript.$MACHINE?

Seems that might be reasonable, although IMO it could be done in a subsequent change.

Looks good.

One little nit, LDFLAGS_BIN seems accurate as it's LDFLAGS for the compiler driver to output a binary directly; LD_FLAGS_BIN is the LD_FLAGS for the linker and is still outputting ELF so the name seems to be a slight mismatch.

For reference an lld change to support --oformat binary is in https://reviews.llvm.org/D23769.

This revision was automatically updated to reflect the committed changes.