#include "Config.h"
#include "Error.h"
#include "InputFiles.h"
+#include "SymbolTable.h"
#include "Symbols.h"
#include "lld/Core/TargetOptionsCommandFlags.h"
#include "llvm/ADT/STLExtras.h"
Config->LTOPartitions);
}
-BitcodeCompiler::BitcodeCompiler() : LTOObj(createLTO()) {}
+BitcodeCompiler::BitcodeCompiler() : LTOObj(createLTO()) {
+ for (Symbol *Sym : Symtab->getSymbols()) {
+ StringRef Name = Sym->body()->getName();
+ for (StringRef Prefix : {"__start_", "__stop_"})
+ if (Name.startswith(Prefix))
+ UsedStartStop.insert(Name.substr(Prefix.size()));
+ }
+}
BitcodeCompiler::~BitcodeCompiler() = default;
R.VisibleToRegularObj = Sym->IsUsedInRegularObj ||
(R.Prevailing && Sym->includeInDynsym()) ||
- isValidCIdentifier(ObjSym.getSectionName());
+ UsedStartStop.count(ObjSym.getSectionName());
if (R.Prevailing)
undefine(Sym);
R.LinkerRedefined = Config->RenamedSymbols.count(Sym);
#define LLD_ELF_LTO_H
#include "lld/Core/LLVM.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallString.h"
#include <memory>
#include <vector>
std::unique_ptr<llvm::lto::LTO> LTOObj;
std::vector<SmallString<0>> Buff;
std::vector<std::unique_ptr<MemoryBuffer>> Files;
+ llvm::DenseSet<StringRef> UsedStartStop;
};
} // namespace elf
} // namespace lld
target triple = "x86_64-unknown-linux-gnu"
@foo = hidden global i32 42, section "foo_section"
+@bar = hidden global i32 42, section "bar_section"
+@zed = hidden global i32 42, section "zed_section"
-; CHECK: foo_section PROGBITS
+@__start_foo_section = external global i32
+@__stop_bar_section = external global i32
+
+define i32* @use1() {
+ ret i32* @__start_foo_section
+}
+
+define i32* @use2() {
+ ret i32* @__stop_bar_section
+}
+
+; CHECK-NOT: zed_section
+; CHECK: foo_section PROGBITS
+; CHECK-NEXT: bar_section PROGBITS
+; CHECK-NOT: zed_section