forked from OSchip/llvm-project
Add default search path if -nostdlib is not provided.
Add basic emulation mapping for NetBSD/amd64, so that clang -m32 works as expected. llvm-svn: 198337
This commit is contained in:
parent
66c20f344e
commit
4dcee6960f
|
@ -73,6 +73,12 @@ public:
|
|||
|
||||
private:
|
||||
static llvm::Triple getDefaultTarget(const char *progName);
|
||||
static bool applyEmulation(llvm::Triple &triple,
|
||||
llvm::opt::InputArgList &args,
|
||||
raw_ostream &diagnostics);
|
||||
static void addPlatformSearchDirs(ELFLinkingContext &ctx,
|
||||
llvm::Triple &triple,
|
||||
llvm::Triple &baseTriple);
|
||||
|
||||
GnuLdDriver() LLVM_DELETED_FUNCTION;
|
||||
};
|
||||
|
|
|
@ -123,6 +123,62 @@ bool GnuLdDriver::linkELF(int argc, const char *argv[],
|
|||
return link(*options, diagnostics);
|
||||
}
|
||||
|
||||
bool GnuLdDriver::applyEmulation(llvm::Triple &triple,
|
||||
llvm::opt::InputArgList &args,
|
||||
raw_ostream &diagnostics) {
|
||||
llvm::opt::Arg *arg = args.getLastArg(OPT_m);
|
||||
if (!arg)
|
||||
return true;
|
||||
std::string value(arg->getValue());
|
||||
|
||||
switch (triple.getOS()) {
|
||||
case llvm::Triple::NetBSD:
|
||||
switch (triple.getArch()) {
|
||||
case llvm::Triple::x86:
|
||||
case llvm::Triple::x86_64:
|
||||
if (value == "elf_i386") {
|
||||
triple.setArch(llvm::Triple::x86);
|
||||
return true;
|
||||
}
|
||||
if (value == "elf_x86_64") {
|
||||
triple.setArch(llvm::Triple::x86_64);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
diagnostics << "error: unsupported emulation '" << value << "'.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
void GnuLdDriver::addPlatformSearchDirs(ELFLinkingContext &ctx,
|
||||
llvm::Triple &triple,
|
||||
llvm::Triple &baseTriple) {
|
||||
switch (triple.getOS()) {
|
||||
case llvm::Triple::NetBSD:
|
||||
switch (triple.getArch()) {
|
||||
case llvm::Triple::x86:
|
||||
if (baseTriple.getArch() == llvm::Triple::x86_64) {
|
||||
ctx.addSearchPath("=/usr/lib/i386");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ctx.addSearchPath("=/usr/lib");
|
||||
}
|
||||
|
||||
bool GnuLdDriver::parse(int argc, const char *argv[],
|
||||
std::unique_ptr<ELFLinkingContext> &context,
|
||||
raw_ostream &diagnostics) {
|
||||
|
@ -148,11 +204,16 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
}
|
||||
|
||||
// Use -target or use default target triple to instantiate LinkingContext
|
||||
llvm::Triple triple;
|
||||
llvm::Triple baseTriple;
|
||||
if (llvm::opt::Arg *trip = parsedArgs->getLastArg(OPT_target))
|
||||
triple = llvm::Triple(trip->getValue());
|
||||
baseTriple = llvm::Triple(trip->getValue());
|
||||
else
|
||||
triple = getDefaultTarget(argv[0]);
|
||||
baseTriple = getDefaultTarget(argv[0]);
|
||||
llvm::Triple triple(baseTriple);
|
||||
|
||||
if (!applyEmulation(triple, *parsedArgs, diagnostics))
|
||||
return false;
|
||||
|
||||
std::unique_ptr<ELFLinkingContext> ctx(ELFLinkingContext::create(triple));
|
||||
|
||||
if (!ctx) {
|
||||
|
@ -187,6 +248,9 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
|
|||
it != ie; ++it)
|
||||
ctx->addSearchPath((*it)->getValue());
|
||||
|
||||
if (!parsedArgs->hasArg(OPT_nostdlib))
|
||||
addPlatformSearchDirs(*ctx, triple, baseTriple);
|
||||
|
||||
// Figure out output kind ( -r, -static, -shared)
|
||||
if ( llvm::opt::Arg *kind = parsedArgs->getLastArg(OPT_relocatable, OPT_static,
|
||||
OPT_shared, OPT_nmagic,
|
||||
|
|
|
@ -54,8 +54,8 @@ def target : Separate<["-"], "target">, MetaVarName<"<triple>">,
|
|||
def output : Separate<["-"], "o">, MetaVarName<"<path>">,
|
||||
HelpText<"Path to file to write output">,
|
||||
Group<grp_general>;
|
||||
def m : Separate<["-"], "m">,
|
||||
HelpText<"Emulate the emulation linker">,
|
||||
def m : Separate<["-"], "m">, MetaVarName<"<emulation>">,
|
||||
HelpText<"Select target emulation">,
|
||||
Group<grp_general>;
|
||||
def build_id : Flag<["--"], "build-id">,
|
||||
HelpText<"Request creation of \".note.gnu.build-id\" ELF note section">,
|
||||
|
@ -95,6 +95,9 @@ def whole_archive: Flag<["--"], "whole-archive">,
|
|||
def no_whole_archive: Flag<["--"], "no-whole-archive">,
|
||||
HelpText<"Restores the default behavior of loading archive members">,
|
||||
Group<grp_main>;
|
||||
def nostdlib : Flag<["-"], "nostdlib">,
|
||||
HelpText<"Disable default search path for libraries">,
|
||||
Group<grp_main>;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// Static Executable Options
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
!<arch>
|
|
@ -0,0 +1 @@
|
|||
!<arch>
|
|
@ -1,6 +1,24 @@
|
|||
RUN: not lld -flavor gnu -t -lfnarchive -L%p/../elf/Inputs 2> %t.err
|
||||
RUN: FileCheck %s < %t.err
|
||||
|
||||
RUN: not lld -flavor gnu -target x86_64--netbsd -t -ltest \
|
||||
RUN: --sysroot=%p/Inputs 2> %t2
|
||||
RUN: FileCheck -check-prefix=NETBSD-AMD64 %s < %t2
|
||||
RUN: not lld -flavor gnu -target x86_64--netbsd -nostdlib -t -ltest \
|
||||
RUN: --sysroot=%p/Inputs 2> %t3
|
||||
RUN: FileCheck -check-prefix=NETBSD-AMD64-NS %s < %t3
|
||||
RUN: not lld -flavor gnu -target i386--netbsd -t -ltest \
|
||||
RUN: --sysroot=%p/Inputs 2> %t4
|
||||
RUN: FileCheck -check-prefix=NETBSD-I386 %s < %t4
|
||||
RUN: not lld -flavor gnu -target x86_64--netbsd -m elf_i386 -t -ltest \
|
||||
RUN: --sysroot=%p/Inputs 2> %t5
|
||||
RUN: FileCheck -check-prefix=NETBSD-AMD64_32 %s < %t5
|
||||
|
||||
# run linker with -t mode to dump full paths to input files
|
||||
|
||||
CHECK: {{[^ ]+}}elf/Inputs{{[\\/]}}libfnarchive.a
|
||||
CHECK: {{[^ ]+}}elf{{[\\/]}}Inputs{{[\\/]}}libfnarchive.a
|
||||
|
||||
NETBSD-AMD64: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}libtest.a
|
||||
NETBSD-AMD64-NS-NOT: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}libtest.a
|
||||
NETBSD-I386: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}libtest.a
|
||||
NETBSD-AMD64_32: {{[^ ]+}}{{[\\/]}}Inputs{{[\\/]}}usr{{[\\/]}}lib{{[\\/]}}i386{{[\\/]}}libtest.a
|
||||
|
|
Loading…
Reference in New Issue