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

Enable gc-sections on FreeBSD when not using old ld.bfd linker #3106

Merged
merged 1 commit into from
Aug 24, 2019

Conversation

valpackett
Copy link
Contributor

(Requires #3105 for isLldDefaultLinker)

The ancient ld.bfd doesn't like this:

.dub/obj/dtest.o: In function `ldc.register_dso':
app.d:(.text.ldc.register_dso+0x1c): undefined reference to `__stop___minfo'
app.d:(.text.ldc.register_dso+0x28): undefined reference to `__start___minfo'
/usr/bin/ld.bfd: .dub/build/application-release-posix.freebsd-x86_64-ldc_2086-54657107D68790E5698D25167B20AC6A/dtest: hidden symbol `__start___minfo' isn't defined
/usr/bin/ld.bfd: final link failed: Nonrepresentable section on output

(miiight be the same bug that's mentioned in the context of PGO on Linux)

but other linkers are of course fine, so let's just enable it when we know BFD is not used. (Eventually it won't be used by default at all: as of FreeBSD 12, LLD is default on amd64 and aarch64 already.)

if (!noLinkerStripDead && (triple.getOS() == llvm::Triple::Linux ||
triple.getOS() == llvm::Triple::FreeBSD ||
triple.getOS() == llvm::Triple::Win32)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ all: Is there a good reason for this OS-specific white-list wrt. separate sections by default? Can't we just make it a blacklist and exclude OSX, or could that break things down on more exotic BSDs etc.? I'm just thinking that it's easier to add a -L--gc-sections manually on those platforms (linker cmdline only!), instead of having to figure out that -data-sections -function-sections is required too in each cmdline, in order to reduce the binary size...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the comment, you'd also have to blacklist MinGW.

OpenBSD has adopted LLD too (in 6.5 for amd64 and i386, on aarch64 probably since the beginning because that Last GPLv2 BFD Version predates aarch64, on other architectures not yet), DFly and NetBSD seem to still have That as the default linker.

IIRC That BFD Bug only happens when actually doing gc-sections, so always emitting function-sections on these OSes should be okay.

Copy link
Member

@kinke kinke Aug 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrt. separate sections by default

That was inaccurate; this block here overrides the LLVM defaults or user-provided cmdline options.

so always emitting function-sections on these OSes should be okay

Thx. LLVM also defaults to separate sections for WebAssembly.
So I think enforcing separate sections with (default) -disable-linker-strip-dead=false for all targets except OSX should be fine. If the linker somehow doesn't like it, the user can still disable it in the cmdline.

@kinke kinke merged commit d13ae13 into ldc-developers:master Aug 24, 2019
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

Successfully merging this pull request may close these issues.

None yet

2 participants