ELF2: Implement --as-needed.
This patch adds AsNeeded and IsUsed bool fields to SharedFile. AsNeeded bit
is set if the DSO is enclosed with --as-needed and --no-as-needed. IsUsed
bit is off by default. When we adds a symbol to the symbol table for dynamic
linking, we set its SharedFile's IsUsed bit.
If AsNeeded is set but IsUsed is not set, we don't want to write that
file's SO name to DT_NEEDED field.
http://reviews.llvm.org/D13579
llvm-svn: 249998
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index e1c2641..933b6be 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -155,12 +155,15 @@
void LinkerScript::readAsNeeded() {
expect("(");
+ bool Orig = Config->AsNeeded;
+ Config->AsNeeded = true;
for (;;) {
StringRef Tok = next();
if (Tok == ")")
- return;
+ break;
addFile(Tok);
}
+ Config->AsNeeded = Orig;
}
void LinkerScript::readEntry() {