forked from OSchip/llvm-project
If lld is renamed (or symlinked) to "ld" automatically pick the right flavor.
The existing system linkers on Darwin and Linux are called "ld". We'd like to eventually drop in lld as "ld" and have it just work. But lld is a universal linker that requires the first option to be -flavor to know which command line mode to emulate (gnu or darwin). This change tests if argv[0] is "ld" and if so, if the tool was built on MacOSX then assume the darwin flavor otherwise the gnu flavor. There are two test cases which copy lld to "ld" and then run it. One for darwin and one for linux. llvm-svn: 217566
This commit is contained in:
parent
292303dd47
commit
50bda292c8
|
@ -89,13 +89,7 @@ static Flavor strToFlavor(StringRef str) {
|
|||
.Case("lld-link", Flavor::win_link)
|
||||
.Case("darwin", Flavor::darwin_ld)
|
||||
.Case("core", Flavor::core)
|
||||
#if __APPLE__
|
||||
// On a Darwin systems, if linker binary is named "ld", use Darwin driver.
|
||||
.Case("ld", Flavor::darwin_ld)
|
||||
#else
|
||||
// On other *nix systems, if linker binary is named "ld", use gnu driver.
|
||||
.Case("ld", Flavor::gnu_ld)
|
||||
#endif
|
||||
.Default(Flavor::invalid);
|
||||
}
|
||||
|
||||
|
@ -160,6 +154,17 @@ bool UniversalDriver::link(int argc, const char *argv[],
|
|||
|
||||
Flavor flavor;
|
||||
|
||||
#if LLVM_ON_UNIX
|
||||
if (llvm::sys::path::filename(argv[0]).equals("ld")) {
|
||||
#if __APPLE__
|
||||
// On a Darwin systems, if linker binary is named "ld", use Darwin driver.
|
||||
flavor = Flavor::darwin_ld;
|
||||
#else
|
||||
// On a ELF based systems, if linker binary is named "ld", use gnu driver.
|
||||
flavor = Flavor::gnu_ld;
|
||||
#endif
|
||||
} else
|
||||
#endif
|
||||
if (parsedArgs->getLastArg(OPT_core)) {
|
||||
flavor = Flavor::core;
|
||||
argv++;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
REQUIRES: system-linker-elf
|
||||
|
||||
RUN: mkdir -p %t.dir && cp `which lld` %t.dir/ld
|
||||
RUN: %t.dir/ld -target x86_64-linux -o %t %p/Inputs/relocs.x86-64 \
|
||||
RUN: -e _start -static
|
||||
RUN: llvm-readobj -t %t | FileCheck %s
|
||||
|
||||
# Test linker run as "ld" on elf based system works like gnu linker.
|
||||
|
||||
|
||||
CHECK: Symbol {
|
||||
CHECK: Name: i
|
||||
CHECK-NEXT: Value:
|
||||
CHECK-NEXT: Size:
|
||||
CHECK-NEXT: Binding:
|
||||
CHECK-NEXT: Type: Object
|
|
@ -124,6 +124,14 @@ if lit_config.useValgrind:
|
|||
if platform.system() not in ['Windows'] or lit_config.getBashPath() != '':
|
||||
config.available_features.add('shell')
|
||||
|
||||
# Running on Darwin OS
|
||||
if platform.system() in ['Darwin']:
|
||||
config.available_features.add('system-linker-mach-o')
|
||||
|
||||
# Running on ELF based *nix
|
||||
if platform.system() in ['Linux']:
|
||||
config.available_features.add('system-linker-elf')
|
||||
|
||||
# llvm-config knows whether it is compiled with asserts (and)
|
||||
# whether we are operating in release/debug mode.
|
||||
import subprocess
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
# REQUIRES: system-linker-mach-o
|
||||
#
|
||||
# RUN: mkdir -p %t.dir && cp `which lld` %t.dir/ld \
|
||||
# RUN: && %t.dir/ld -arch x86_64 -macosx_version_min 10.8 %s -o %t \
|
||||
# RUN: && llvm-nm %t | FileCheck %s
|
||||
#
|
||||
# Test linker run as "ld" on darwin works as darwin linker.
|
||||
#
|
||||
|
||||
--- !mach-o
|
||||
arch: x86_64
|
||||
file-type: MH_OBJECT
|
||||
flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ]
|
||||
has-UUID: false
|
||||
OS: unknown
|
||||
sections:
|
||||
- segment: __TEXT
|
||||
section: __text
|
||||
type: S_REGULAR
|
||||
attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
|
||||
address: 0x0000000000000000
|
||||
content: [ 0xC3 ]
|
||||
global-symbols:
|
||||
- name: _main
|
||||
type: N_SECT
|
||||
scope: [ N_EXT ]
|
||||
sect: 1
|
||||
value: 0x0000000000000000
|
||||
|
||||
--- !mach-o
|
||||
arch: x86_64
|
||||
file-type: MH_DYLIB
|
||||
install-name: /usr/lib/libSystem.B.dylib
|
||||
exports:
|
||||
- name: dyld_stub_binder
|
||||
|
||||
...
|
||||
|
||||
# CHECK: T _main
|
Loading…
Reference in New Issue