summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 03c5fc4fca7..5e56b50e7d4 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -28,8 +28,8 @@ using namespace lld::elf2;
namespace {
class LinkerScript {
public:
- LinkerScript(BumpPtrAllocator *A, StringRef S)
- : Saver(*A), Tokens(tokenize(S)) {}
+ LinkerScript(BumpPtrAllocator *A, StringRef S, bool B)
+ : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {}
void run();
private:
@@ -58,6 +58,7 @@ private:
StringSaver Saver;
std::vector<StringRef> Tokens;
size_t Pos = 0;
+ bool IsUnderSysroot;
};
}
@@ -160,6 +161,15 @@ void LinkerScript::expect(StringRef Expect) {
}
void LinkerScript::addFile(StringRef S) {
+ if (IsUnderSysroot && S.startswith("/")) {
+ SmallString<128> Path;
+ (Config->Sysroot + S).toStringRef(Path);
+ if (sys::fs::exists(Path)) {
+ Driver->addFile(Saver.save(Path.str()));
+ return;
+ }
+ }
+
if (sys::path::is_absolute(S)) {
Driver->addFile(S);
} else if (S.startswith("=")) {
@@ -290,7 +300,17 @@ void LinkerScript::readOutputSectionDescription() {
}
}
+static bool isUnderSysroot(StringRef Path) {
+ if (Config->Sysroot == "")
+ return false;
+ for (; !Path.empty(); Path = sys::path::parent_path(Path))
+ if (sys::fs::equivalent(Config->Sysroot, Path))
+ return true;
+ return false;
+}
+
// Entry point. The other functions or classes are private to this file.
void lld::elf2::readLinkerScript(BumpPtrAllocator *A, MemoryBufferRef MB) {
- LinkerScript(A, MB.getBuffer()).run();
+ StringRef Path = MB.getBufferIdentifier();
+ LinkerScript(A, MB.getBuffer(), isUnderSysroot(Path)).run();
}
OpenPOWER on IntegriCloud