summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2016-02-02 09:28:53 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2016-02-02 09:28:53 +0000
commit5c36e5938dbb2d4c135819189fd68fdb5982850c (patch)
tree8654b9b81ffc4ff91f2dc73f1331349777ac7812
parentffe19f524548fd8b4e16db4c6bd3528850890e00 (diff)
downloadbcm5719-llvm-5c36e5938dbb2d4c135819189fd68fdb5982850c.tar.gz
bcm5719-llvm-5c36e5938dbb2d4c135819189fd68fdb5982850c.zip
[ELF] Implemented -Bsymbolic-functions command line option
-Bsymbolic-functions: When creating a shared library, bind references to global function symbols to the definition within the shared library, if any. This patch also fixed behavior of already existent -Bsymbolic: previously PLT entries were created even if -Bsymbolic was specified. Differential revision: http://reviews.llvm.org/D16411 llvm-svn: 259481
-rw-r--r--lld/ELF/Config.h1
-rw-r--r--lld/ELF/Driver.cpp1
-rw-r--r--lld/ELF/Options.td3
-rw-r--r--lld/ELF/OutputSections.cpp6
-rw-r--r--lld/ELF/Symbols.cpp13
-rw-r--r--lld/ELF/Symbols.h15
-rw-r--r--lld/test/ELF/bsymbolic.s30
7 files changed, 58 insertions, 11 deletions
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 0b92dba0fb1..e9113aca180 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -53,6 +53,7 @@ struct Configuration {
bool AllowMultipleDefinition;
bool AsNeeded = false;
bool Bsymbolic;
+ bool BsymbolicFunctions;
bool Demangle = true;
bool DiscardAll;
bool DiscardLocals;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 4fbf202c9d2..677d40bd213 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -188,6 +188,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition);
Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);
+ Config->BsymbolicFunctions = Args.hasArg(OPT_Bsymbolic_functions);
Config->Demangle = !Args.hasArg(OPT_no_demangle);
Config->DiscardAll = Args.hasArg(OPT_discard_all);
Config->DiscardLocals = Args.hasArg(OPT_discard_locals);
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 0d649894bc9..40bab6a0d57 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -3,6 +3,9 @@ include "llvm/Option/OptParser.td"
def Bsymbolic: Flag<["-"], "Bsymbolic">,
HelpText<"Bind defined symbols locally">;
+def Bsymbolic_functions: Flag<["-"], "Bsymbolic-functions">,
+ HelpText<"Bind defined function symbols locally">;
+
def Bdynamic: Flag<["-"], "Bdynamic">,
HelpText<"Link against shared libraries">;
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 68992bd32c3..d8ec21c722a 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -895,7 +895,11 @@ bool elf2::canBePreempted(const SymbolBody *Body, bool NeedsGot) {
}
if (!Config->Shared)
return false;
- return Body->getVisibility() == STV_DEFAULT;
+ if (Body->getVisibility() != STV_DEFAULT)
+ return false;
+ if (Config->Bsymbolic || (Config->BsymbolicFunctions && Body->isFunc()))
+ return false;
+ return true;
}
template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index c8b8891b6b1..30b086f68db 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -146,12 +146,13 @@ template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
}
Defined::Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility,
- bool IsTls)
- : SymbolBody(K, Name, IsWeak, Visibility, IsTls) {}
+ bool IsTls, bool IsFunction)
+ : SymbolBody(K, Name, IsWeak, Visibility, IsTls, IsFunction) {}
Undefined::Undefined(SymbolBody::Kind K, StringRef N, bool IsWeak,
uint8_t Visibility, bool IsTls)
- : SymbolBody(K, N, IsWeak, Visibility, IsTls), CanKeepUndefined(false) {}
+ : SymbolBody(K, N, IsWeak, Visibility, IsTls, /*IsFunction*/ false),
+ CanKeepUndefined(false) {}
Undefined::Undefined(StringRef N, bool IsWeak, uint8_t Visibility,
bool CanKeepUndefined)
@@ -170,12 +171,14 @@ UndefinedElf<ELFT>::UndefinedElf(StringRef N, const Elf_Sym &Sym)
template <typename ELFT>
DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value,
OutputSectionBase<ELFT> &Section)
- : Defined(SymbolBody::DefinedSyntheticKind, N, false, STV_DEFAULT, false),
+ : Defined(SymbolBody::DefinedSyntheticKind, N, false, STV_DEFAULT,
+ /*IsTls*/ false, /*IsFunction*/ false),
Value(Value), Section(Section) {}
DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment,
bool IsWeak, uint8_t Visibility)
- : Defined(SymbolBody::DefinedCommonKind, N, IsWeak, Visibility, false) {
+ : Defined(SymbolBody::DefinedCommonKind, N, IsWeak, Visibility,
+ /*IsTls*/ false, /*IsFunction*/ false) {
MaxAlignment = Alignment;
this->Size = Size;
}
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 67cbaa327f3..af16124a763 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -86,6 +86,7 @@ public:
bool isUsedInDynamicReloc() const { return IsUsedInDynamicReloc; }
void setUsedInDynamicReloc() { IsUsedInDynamicReloc = true; }
bool isTls() const { return IsTls; }
+ bool isFunc() const { return IsFunc; }
// Returns the symbol name.
StringRef getName() const { return Name; }
@@ -127,9 +128,9 @@ public:
protected:
SymbolBody(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility,
- bool IsTls)
+ bool IsTls, bool IsFunc)
: SymbolKind(K), IsWeak(IsWeak), Visibility(Visibility), IsTls(IsTls),
- Name(Name) {
+ IsFunc(IsFunc), Name(Name) {
IsUsedInRegularObj = K != SharedKind && K != LazyKind;
IsUsedInDynamicReloc = 0;
}
@@ -148,6 +149,7 @@ protected:
unsigned IsUsedInDynamicReloc : 1;
unsigned IsTls : 1;
+ unsigned IsFunc : 1;
StringRef Name;
Symbol *Backref = nullptr;
};
@@ -155,7 +157,8 @@ protected:
// The base class for any defined symbols.
class Defined : public SymbolBody {
public:
- Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility, bool IsTls);
+ Defined(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility, bool IsTls,
+ bool IsFunction);
static bool classof(const SymbolBody *S) { return S->isDefined(); }
};
@@ -167,7 +170,8 @@ protected:
public:
DefinedElf(Kind K, StringRef N, const Elf_Sym &Sym)
: Defined(K, N, Sym.getBinding() == llvm::ELF::STB_WEAK,
- Sym.getVisibility(), Sym.getType() == llvm::ELF::STT_TLS),
+ Sym.getVisibility(), Sym.getType() == llvm::ELF::STT_TLS,
+ Sym.getType() == llvm::ELF::STT_FUNC),
Sym(Sym) {}
const Elf_Sym &Sym;
@@ -289,7 +293,8 @@ public:
class Lazy : public SymbolBody {
public:
Lazy(ArchiveFile *F, const llvm::object::Archive::Symbol S)
- : SymbolBody(LazyKind, S.getName(), false, llvm::ELF::STV_DEFAULT, false),
+ : SymbolBody(LazyKind, S.getName(), false, llvm::ELF::STV_DEFAULT,
+ /*IsTls*/ false, /*IsFunction*/ false),
File(F), Sym(S) {}
static bool classof(const SymbolBody *S) { return S->kind() == LazyKind; }
diff --git a/lld/test/ELF/bsymbolic.s b/lld/test/ELF/bsymbolic.s
new file mode 100644
index 00000000000..3929d7bae3b
--- /dev/null
+++ b/lld/test/ELF/bsymbolic.s
@@ -0,0 +1,30 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: ld.lld -shared %t.o -o %t0.so
+// RUN: ld.lld -shared -Bsymbolic %t.o -o %t1.so
+// RUN: ld.lld -shared -Bsymbolic-functions %t.o -o %t2.so
+// RUN: llvm-readobj -s %t0.so | FileCheck -check-prefix=NOOPTION %s
+// RUN: llvm-readobj -s %t1.so | FileCheck -check-prefix=SYMBOLIC %s
+// RUN: llvm-readobj -s %t2.so | FileCheck -check-prefix=SYMBOLIC %s
+
+// NOOPTION: Section {
+// NOOPTION: Name: .plt
+
+// SYMBOLIC: Section {
+// SYMBOLIC-NOT: Name: .plt
+
+.text
+.globl foo
+.type foo,@function
+foo:
+nop
+
+.globl bar
+.type bar,@function
+bar:
+nop
+
+.globl do
+.type do,@function
+do:
+callq foo@PLT
+callq bar@PLT
OpenPOWER on IntegriCloud