Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,7 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
nextGroupId = 0;
isInGroup = false;
bool hasInput = false, hasScript = false;
StringRef scriptFilePath, defaultScriptFilePath;
for (auto *arg : args) {
switch (arg->getOption().getID()) {
case OPT_library:
Expand All @@ -2106,7 +2107,11 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
break;
}
case OPT_script:
scriptFilePath = arg->getValue();
[[fallthrough]];
case OPT_default_script:
if (arg->getOption().matches(OPT_default_script))
defaultScriptFilePath = arg->getValue();
if (std::optional<std::string> path =
searchScript(ctx, arg->getValue())) {
if (std::optional<MemoryBufferRef> mb = readFile(ctx, *path)) {
Expand Down Expand Up @@ -2201,6 +2206,10 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {

if (defaultScript && !hasScript)
readLinkerScript(ctx, *defaultScript);
if (defaultScript && hasScript)
Warn(ctx) << "--script at path " << scriptFilePath
<< " will override --default-script at path "
<< defaultScriptFilePath;
if (files.empty() && !hasInput && errCount(ctx) == 0)
ErrAlways(ctx) << "no input files";
}
Expand Down
10 changes: 10 additions & 0 deletions lld/test/ELF/linkerscript/default-script.s
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
# CHECK1-NEXT: 3: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS def
# CHECK1-EMPTY:

## When both --script and --default-script are specified, --script overrides
## --default-script.
# RUN: ld.lld --default-script def.t --script b.t a.o -o out2 2>warn.txt
# RUN: llvm-readelf -Ss out2 | FileCheck %s --check-prefix=OVERRIDE
# OVERRIDE: .foo0
# OVERRIDE-NEXT: foo1
# OVERRIDE-NEXT: foo2
# RUN: cat warn.txt | FileCheck %s --check-prefix=WARNING
# WARNING: --script at path b.t will override --default-script at path def.t

# RUN: not ld.lld --default-script not-exist.t b.t -T a.t a.o 2>&1 | FileCheck %s --check-prefix=ERR
# ERR: error: cannot find linker script not-exist.t

Expand Down