Index: lib/Driver/UniversalDriver.cpp =================================================================== --- lib/Driver/UniversalDriver.cpp +++ lib/Driver/UniversalDriver.cpp @@ -89,13 +89,7 @@ .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 @@ 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++; Index: test/elf/linker-as-ld.test =================================================================== --- /dev/null +++ test/elf/linker-as-ld.test @@ -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 Index: test/lit.cfg =================================================================== --- test/lit.cfg +++ test/lit.cfg @@ -124,6 +124,14 @@ 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 Index: test/mach-o/linker-as-ld.yaml =================================================================== --- /dev/null +++ test/mach-o/linker-as-ld.yaml @@ -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