summaryrefslogtreecommitdiff
path: root/lib/LTO
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-01-14 18:52:17 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-01-14 18:52:17 +0000
commit3e4542b2ca3426e5f5b812e008f6c71cf9ad295b (patch)
treeaabc4dfbe82b7dfb4c91a4390d86e7f136cba13d /lib/LTO
parentcba390a29ed0839aae92e010229b07a5ebb82438 (diff)
downloadllvm-3e4542b2ca3426e5f5b812e008f6c71cf9ad295b.tar.gz
llvm-3e4542b2ca3426e5f5b812e008f6c71cf9ad295b.tar.bz2
llvm-3e4542b2ca3426e5f5b812e008f6c71cf9ad295b.tar.xz
Reapply "LTO: add API to set strategy for -internalize"
Reapply r199191, reverted in r199197 because it carelessly broke Other/link-opts.ll. The problem was that calling createInternalizePass("main") would select createInternalizePass(bool("main")) instead of createInternalizePass(ArrayRef<const char *>("main")). This commit fixes the bug. The original commit message follows. Add API to LTOCodeGenerator to specify a strategy for the -internalize pass. This is a new attempt at Bill's change in r185882, which he reverted in r188029 due to problems with the gold linker. This puts the onus on the linker to decide whether (and what) to internalize. In particular, running internalize before outputting an object file may change a 'weak' symbol into an internal one, even though that symbol could be needed by an external object file --- e.g., with arclite. This patch enables three strategies: - LTO_INTERNALIZE_FULL: the default (and the old behaviour). - LTO_INTERNALIZE_NONE: skip -internalize. - LTO_INTERNALIZE_HIDDEN: only -internalize symbols with hidden visibility. LTO_INTERNALIZE_FULL should be used when linking an executable. Outputting an object file (e.g., via ld -r) is more complicated, and depends on whether hidden symbols should be internalized. E.g., for ld -r, LTO_INTERNALIZE_NONE can be used when -keep_private_externs, and LTO_INTERNALIZE_HIDDEN can be used otherwise. However, LTO_INTERNALIZE_FULL is inappropriate, since the output object file will eventually need to link with others. lto_codegen_set_internalize_strategy() sets the strategy for subsequent calls to lto_codegen_write_merged_modules() and lto_codegen_compile*(). <rdar://problem/14334895> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199244 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/LTO')
-rw-r--r--lib/LTO/LTOCodeGenerator.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp
index 59d5a791be..8d84a8b525 100644
--- a/lib/LTO/LTOCodeGenerator.cpp
+++ b/lib/LTO/LTOCodeGenerator.cpp
@@ -62,7 +62,8 @@ const char* LTOCodeGenerator::getVersionString() {
LTOCodeGenerator::LTOCodeGenerator()
: Context(getGlobalContext()), Linker(new Module("ld-temp.o", Context)),
TargetMach(NULL), EmitDwarfDebugInfo(false), ScopeRestrictionsDone(false),
- CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), NativeObjectFile(NULL) {
+ CodeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC),
+ InternalizeStrategy(LTO_INTERNALIZE_FULL), NativeObjectFile(NULL) {
initializeLTOPasses();
}
@@ -164,6 +165,18 @@ void LTOCodeGenerator::setCodePICModel(lto_codegen_model model) {
llvm_unreachable("Unknown PIC model!");
}
+void
+LTOCodeGenerator::setInternalizeStrategy(lto_internalize_strategy Strategy) {
+ switch (Strategy) {
+ case LTO_INTERNALIZE_FULL:
+ case LTO_INTERNALIZE_NONE:
+ case LTO_INTERNALIZE_HIDDEN:
+ InternalizeStrategy = Strategy;
+ return;
+ }
+ llvm_unreachable("Unknown internalize strategy!");
+}
+
bool LTOCodeGenerator::writeMergedModules(const char *path,
std::string &errMsg) {
if (!determineTarget(errMsg))
@@ -377,7 +390,7 @@ static void accumulateAndSortLibcalls(std::vector<StringRef> &Libcalls,
}
void LTOCodeGenerator::applyScopeRestrictions() {
- if (ScopeRestrictionsDone)
+ if (ScopeRestrictionsDone || !shouldInternalize())
return;
Module *mergedModule = Linker.getModule();
@@ -429,7 +442,8 @@ void LTOCodeGenerator::applyScopeRestrictions() {
LLVMCompilerUsed->setSection("llvm.metadata");
}
- passes.add(createInternalizePass(MustPreserveList));
+ passes.add(
+ createInternalizePass(MustPreserveList, shouldOnlyInternalizeHidden()));
// apply scope restrictions
passes.run(*mergedModule);