mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 01:20:51 +03:00
Be less conservative wrt. linker dead code elimination
This commit is contained in:
parent
95ac5cadb8
commit
aa9eb33cb1
3 changed files with 22 additions and 21 deletions
|
@ -479,6 +479,8 @@ void ArgsBuilder::addSanitizers(const llvm::Triple &triple) {
|
|||
|
||||
void ArgsBuilder::build(llvm::StringRef outputPath,
|
||||
const std::vector<std::string> &defaultLibNames) {
|
||||
const auto &triple = *global.params.targetTriple;
|
||||
|
||||
// object files
|
||||
for (auto objfile : global.params.objfiles) {
|
||||
args.push_back(objfile);
|
||||
|
@ -494,7 +496,7 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
|
|||
|
||||
// Link with profile-rt library when generating an instrumented binary.
|
||||
if (opts::isInstrumentingForPGO()) {
|
||||
addProfileRuntimeLinkFlags(*global.params.targetTriple);
|
||||
addProfileRuntimeLinkFlags(triple);
|
||||
}
|
||||
|
||||
if (opts::enableDynamicCompile) {
|
||||
|
@ -521,10 +523,10 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
|
|||
args.push_back("-o");
|
||||
args.push_back(std::string(outputPath));
|
||||
|
||||
addSanitizers(*global.params.targetTriple);
|
||||
addSanitizers(triple);
|
||||
|
||||
if (opts::fXRayInstrument) {
|
||||
addXRayLinkFlags(*global.params.targetTriple);
|
||||
addXRayLinkFlags(triple);
|
||||
}
|
||||
|
||||
// Add LTO link flags before adding the user link switches, such that the user
|
||||
|
@ -559,16 +561,14 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
|
|||
addLdFlag("-rpath", rpath);
|
||||
}
|
||||
|
||||
if (global.params.targetTriple->getOS() == llvm::Triple::Linux ||
|
||||
(global.params.targetTriple->getOS() == llvm::Triple::FreeBSD &&
|
||||
(useInternalLLDForLinking() ||
|
||||
(!opts::linker.empty() && opts::linker != "bfd") ||
|
||||
(opts::linker.empty() && isLldDefaultLinker())))) {
|
||||
// Make sure we don't do --gc-sections when generating a profile-
|
||||
// instrumented binary. The runtime relies on magic sections, which
|
||||
// would be stripped by gc-section on older version of ld, see bug:
|
||||
// https://sourceware.org/bugzilla/show_bug.cgi?id=19161
|
||||
if (!opts::disableLinkerStripDead && !opts::isInstrumentingForPGO()) {
|
||||
// Make sure we don't do --gc-sections when generating a profile-
|
||||
// instrumented binary. The runtime relies on magic sections, which
|
||||
// would be stripped by gc-section on older version of ld, see bug:
|
||||
// https://sourceware.org/bugzilla/show_bug.cgi?id=19161
|
||||
if (!opts::disableLinkerStripDead && !opts::isInstrumentingForPGO()) {
|
||||
if (triple.isOSBinFormatMachO()) {
|
||||
addLdFlag("-dead_strip");
|
||||
} else {
|
||||
addLdFlag("--gc-sections");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue