[lld] r309232 - Make __start_sec __end_sec handling more precise.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 16:39:10 PDT 2017
Author: rafael
Date: Wed Jul 26 16:39:10 2017
New Revision: 309232
URL: http://llvm.org/viewvc/llvm-project?rev=309232&view=rev
Log:
Make __start_sec __end_sec handling more precise.
With this we only ask LTO to keep a C named section if there is a
__start_ or __end symbol.
This is not as strict as lld's --gc-sections, but is as good as we can
get without having a far more detailed ir summary.
Modified:
lld/trunk/ELF/LTO.cpp
lld/trunk/ELF/LTO.h
lld/trunk/test/ELF/lto/section-name.ll
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=309232&r1=309231&r2=309232&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Wed Jul 26 16:39:10 2017
@@ -11,6 +11,7 @@
#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"
@@ -107,7 +108,14 @@ static std::unique_ptr<lto::LTO> createL
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;
@@ -138,7 +146,7 @@ void BitcodeCompiler::add(BitcodeFile &F
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);
Modified: lld/trunk/ELF/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?rev=309232&r1=309231&r2=309232&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.h (original)
+++ lld/trunk/ELF/LTO.h Wed Jul 26 16:39:10 2017
@@ -22,6 +22,7 @@
#define LLD_ELF_LTO_H
#include "lld/Core/LLVM.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallString.h"
#include <memory>
#include <vector>
@@ -50,6 +51,7 @@ private:
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
Modified: lld/trunk/test/ELF/lto/section-name.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/section-name.ll?rev=309232&r1=309231&r2=309232&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/section-name.ll (original)
+++ lld/trunk/test/ELF/lto/section-name.ll Wed Jul 26 16:39:10 2017
@@ -7,5 +7,21 @@ target datalayout = "e-m:e-i64:64-f80:12
target triple = "x86_64-unknown-linux-gnu"
@foo = hidden global i32 42, section "foo_section"
+ at bar = hidden global i32 42, section "bar_section"
+ at zed = hidden global i32 42, section "zed_section"
-; CHECK: foo_section PROGBITS
+ at __start_foo_section = external global i32
+ at __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
More information about the llvm-commits
mailing list