llvm.org GIT mirror llvm / 75fb58c
Symbols re-defined with -wrap and -defsym need to be excluded from inter- procedural optimizations to prevent dropping symbols and allow the linker to process re-directs. PR33145: --wrap doesn't work with lto. Differential Revision: https://reviews.llvm.org/D33621 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304719 91177308-0d34-0410-b5e6-96231b3b80d8 Dmitry Mikulin 3 years ago
4 changed file(s) with 38 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
365365 /// each global symbol based on its internal resolution of that symbol.
366366 struct SymbolResolution {
367367 SymbolResolution()
368 : Prevailing(0), FinalDefinitionInLinkageUnit(0), VisibleToRegularObj(0) {
369 }
368 : Prevailing(0), FinalDefinitionInLinkageUnit(0), VisibleToRegularObj(0),
369 LinkerRedefined(0) {}
370
370371 /// The linker has chosen this definition of the symbol.
371372 unsigned Prevailing : 1;
372373
376377
377378 /// The definition of this symbol is visible outside of the LTO unit.
378379 unsigned VisibleToRegularObj : 1;
380
381 /// Linker redefined version of the symbol which appeared in -wrap or -defsym
382 /// linker option.
383 unsigned LinkerRedefined : 1;
379384 };
380385
381386 } // namespace lto
404404 if (Res.Prevailing)
405405 GlobalRes.IRName = Sym.getIRName();
406406
407 // Set the partition to external if we know it is used elsewhere, e.g.
408 // it is visible to a regular object, is referenced from llvm.compiler_used,
409 // or was already recorded as being referenced from a different partition.
410 if (Res.VisibleToRegularObj || Sym.isUsed() ||
407 // Set the partition to external if we know it is re-defined by the linker
408 // with -defsym or -wrap options, used elsewhere, e.g. it is visible to a
409 // regular object, is referenced from llvm.compiler_used, or was already
410 // recorded as being referenced from a different partition.
411 if (Res.LinkerRedefined || Res.VisibleToRegularObj || Sym.isUsed() ||
411412 (GlobalRes.Partition != GlobalResolution::Unknown &&
412413 GlobalRes.Partition != Partition)) {
413414 GlobalRes.Partition = GlobalResolution::External;
438439 OS << 'l';
439440 if (Res.VisibleToRegularObj)
440441 OS << 'x';
442 if (Res.LinkerRedefined)
443 OS << 'r';
441444 OS << '\n';
442445 }
443446 OS.flush();
542545 if (Sym.isUndefined())
543546 continue;
544547 Keep.push_back(GV);
548 // For symbols re-defined with linker -wrap and -defsym options,
549 // set the linkage to weak to inhibit IPO. The linkage will be
550 // restored by the linker.
551 if (Res.LinkerRedefined)
552 GV->setLinkage(GlobalValue::WeakAnyLinkage);
553
545554 GlobalValue::LinkageTypes OriginalLinkage = GV->getLinkage();
546555 if (GlobalValue::isLinkOnceLinkage(OriginalLinkage))
547556 GV->setLinkage(GlobalValue::getWeakLinkage(
0 ; RUN: llvm-as %s -o %t.o
1 ; RUN: llvm-lto2 run -o %t1.o %t.o -r %t.o,bar,pr
2 ; RUN: llvm-readobj -t %t1.o.0 | FileCheck %s
3
4 ; CHECK: Name: bar
5 ; CHECK-NEXT: Value:
6 ; CHECK-NEXT: Size:
7 ; CHECK-NEXT: Binding: Weak
8 ; CHECK-NEXT: Type: Function
9
10 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
11 target triple = "x86_64-unknown-linux-gnu"
12
13 define void @bar() {
14 ret void
15 }
161161 Res.FinalDefinitionInLinkageUnit = true;
162162 else if (C == 'x')
163163 Res.VisibleToRegularObj = true;
164 else if (C == 'r')
165 Res.LinkerRedefined = true;
164166 else {
165167 llvm::errs() << "invalid character " << C << " in resolution: " << R
166168 << '\n';