[PATCH] D85309: [Driver] Support GNU ld on Solaris
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGd39a9e3b4d4a: [Driver] Support GNU ld on Solaris (authored by ro). Changed prior to commit: https://reviews.llvm.org/D85309?vs=554946=555463#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/Solaris.cpp clang/lib/Driver/ToolChains/Solaris.h clang/test/Driver/hip-link-bundle-archive.hip clang/test/Driver/solaris-ld-sanitizer.c clang/test/Driver/solaris-ld.c compiler-rt/cmake/config-ix.cmake compiler-rt/test/asan/TestCases/global-location-nodebug.cpp flang/test/Driver/linker-flags.f90 llvm/cmake/modules/AddLLVM.cmake Index: llvm/cmake/modules/AddLLVM.cmake === --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -282,9 +282,9 @@ # ld64's implementation of -dead_strip breaks tools that use plugins. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dead_strip") - elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD) # Support for ld -z discard-unused=sections was only added in -# Solaris 11.4. +# Solaris 11.4. GNU ld ignores it, but warns every time. include(LLVMCheckLinkerFlag) llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) if (LINKER_SUPPORTS_Z_DISCARD_UNUSED) @@ -1281,7 +1281,10 @@ # the size of the exported symbol table, but on other platforms we can do # it without any trouble. set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) -if (APPLE) +# CMake doesn't set CMAKE_EXE_EXPORTS_${lang}_FLAG on Solaris, so +# ENABLE_EXPORTS has no effect. While Solaris ld defaults to -rdynamic +# behaviour, GNU ld needs it. +if (APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -rdynamic") endif() Index: flang/test/Driver/linker-flags.f90 === --- flang/test/Driver/linker-flags.f90 +++ flang/test/Driver/linker-flags.f90 @@ -10,7 +10,7 @@ ! 'oldnames' on Windows, but they are not needed when compiling ! Fortran code and they might bring in additional dependencies. ! Make sure they're not added. -! RUN: %flang -### -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames +! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames ! Compiler invocation to generate the object file ! CHECK-LABEL: {{.*}} "-emit-obj" Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp === --- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp +++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp @@ -2,13 +2,14 @@ /// allow this test to also run on Windows (which can't be done for the /// debuginfo variant). -// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %} +// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %} %if target={{.*-solaris.*}} %{ -fuse-ld= %} // RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB-NO-G // RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC-NO-G // RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC-NO-G // RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL-NO-G -/// Solaris ld -S has different semantics. +/// Solaris ld -S has different semantics, so enforce -fuse-ld= for +/// configurations that default to GNU ld. // XFAIL: target={{.*solaris.*}} // CHECK: AddressSanitizer: global-buffer-overflow Index: compiler-rt/cmake/config-ix.cmake === --- compiler-rt/cmake/config-ix.cmake +++ compiler-rt/cmake/config-ix.cmake @@ -1,4 +1,5 @@ include(CMakePushCheckState) +include(AddLLVM) include(LLVMCheckCompilerLinkerFlag) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) @@ -196,7 +197,7 @@ llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT) llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
[PATCH] D85309: [Driver] Support GNU ld on Solaris
MaskRay accepted this revision. MaskRay added a comment. This revision is now accepted and ready to land. LGTM. Comment at: clang/lib/Driver/ToolChains/Solaris.cpp:55 + StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER; + // FIXME: What about -fuse-ld=? + return UseLinker == "bfd" || UseLinker == "gld"; `-fuse-ld=` is deprecated by `--ld-path=`. So just drop this FIXME. Comment at: clang/lib/Driver/ToolChains/Solaris.cpp:84 +// FIXME: Could also use /usr/bin/gld here. +return std::string("/usr/gnu/bin/ld"); + Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D85309: [Driver] Support GNU ld on Solaris
ro added inline comments. Comment at: clang/test/Driver/hip-link-bundle-archive.hip:59 // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ -// RUN: --target=x86_64-pc-windows-msvc \ +// RUN: --target=x86_64-pc-windows-msvc -fuse-ld= \ // RUN: -nogpuinc -nogpulib %s -fgpu-rdc -L%t -lhipBundled2 \ MaskRay wrote: > Any idea why `-fuse-ld=` is now needed? I've tried to explain it in the change description, but just noticed the filename is wrong: When LLVM is built with `-DCLANG_DEFAULT_LINKER=gld` on Solaris, `MSVC.cpp` `visualstudio::Linker::ConstructJob` sets `Linker` to `gld`. Ultimately, `GetProgramPath(Linker)` is called, resulting in a search for `gld`, which exists in `/usr/bin/gld` on Solaris. With `-fuse-ld=`, this doesn't happen and the expected `link` is returned. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D85309: [Driver] Support GNU ld on Solaris
MaskRay added inline comments. Comment at: clang/test/Driver/hip-link-bundle-archive.hip:59 // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ -// RUN: --target=x86_64-pc-windows-msvc \ +// RUN: --target=x86_64-pc-windows-msvc -fuse-ld= \ // RUN: -nogpuinc -nogpulib %s -fgpu-rdc -L%t -lhipBundled2 \ Any idea why `-fuse-ld=` is now needed? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D85309: [Driver] Support GNU ld on Solaris
ro updated this revision to Diff 554946. ro marked an inline comment as done. ro added a comment. Move `isLinkerGnuLd` to `Solaris.{h,cpp}` and into `solaris` namespace to make it unambigously clear where to use it. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/Solaris.cpp clang/lib/Driver/ToolChains/Solaris.h clang/test/Driver/hip-link-bundle-archive.hip clang/test/Driver/solaris-ld-sanitizer.c clang/test/Driver/solaris-ld.c compiler-rt/cmake/config-ix.cmake compiler-rt/test/asan/TestCases/global-location-nodebug.cpp flang/test/Driver/linker-flags.f90 llvm/cmake/modules/AddLLVM.cmake Index: llvm/cmake/modules/AddLLVM.cmake === --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -282,9 +282,9 @@ # ld64's implementation of -dead_strip breaks tools that use plugins. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dead_strip") - elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD) # Support for ld -z discard-unused=sections was only added in -# Solaris 11.4. +# Solaris 11.4. GNU ld ignores it, but warns every time. include(LLVMCheckLinkerFlag) llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) if (LINKER_SUPPORTS_Z_DISCARD_UNUSED) @@ -1288,7 +1288,10 @@ # the size of the exported symbol table, but on other platforms we can do # it without any trouble. set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) -if (APPLE) +# CMake doesn't set CMAKE_EXE_EXPORTS_${lang}_FLAG on Solaris, so +# ENABLE_EXPORTS has no effect. While Solaris ld defaults to -rdynamic +# behaviour, GNU ld needs it. +if (APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -rdynamic") endif() Index: flang/test/Driver/linker-flags.f90 === --- flang/test/Driver/linker-flags.f90 +++ flang/test/Driver/linker-flags.f90 @@ -10,7 +10,7 @@ ! 'oldnames' on Windows, but they are not needed when compiling ! Fortran code and they might bring in additional dependencies. ! Make sure they're not added. -! RUN: %flang -### -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames +! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames ! Compiler invocation to generate the object file ! CHECK-LABEL: {{.*}} "-emit-obj" Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp === --- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp +++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp @@ -2,13 +2,14 @@ /// allow this test to also run on Windows (which can't be done for the /// debuginfo variant). -// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %} +// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %} %if target={{.*-solaris.*}} %{ -fuse-ld= %} // RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB-NO-G // RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC-NO-G // RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC-NO-G // RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL-NO-G -/// Solaris ld -S has different semantics. +/// Solaris ld -S has different semantics, so enforce -fuse-ld= for +/// configurations that default to GNU ld. // XFAIL: target={{.*solaris.*}} // CHECK: AddressSanitizer: global-buffer-overflow Index: compiler-rt/cmake/config-ix.cmake === --- compiler-rt/cmake/config-ix.cmake +++ compiler-rt/cmake/config-ix.cmake @@ -1,4 +1,5 @@ include(CMakePushCheckState) +include(AddLLVM) include(LLVMCheckCompilerLinkerFlag) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) @@ -196,7 +197,7 @@ llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT) llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG) -if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") +if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND
[PATCH] D85309: [Driver] Support GNU ld on Solaris
ro marked an inline comment as done. ro added inline comments. Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:305 +bool tools::isLinkerGnuLd(const ToolChain , const ArgList ) { + // Only used if targetting Solaris. MaskRay wrote: > I suppose that this should be in a Solaris specific file to indicate that > it's not for other systems. > > GNU ld is almost ubiquitous on Linux and is almost always available at > /usr/bin/ld (with very few distributions using others linkers by default or > providing an option). > > Detecting linker to affect driver decisions is we Linux are very wary of. We > are nervous even trying to do some stuff only related to lld. > > We likely don't want this function to be in CommonArgs to lure other > contributors to use. > I suppose that this should be in a Solaris specific file to indicate that > it's not for other systems. Indeed. I've moved it to `Solaris.{h,cpp}` now. In fact, initially i'd tried to assert a Solaris target in `isLinkerGnuLd`, but that cannot work because in some cases the function is called in common code, even though the result is only used on Solaris. I briefly thought about generalizing both `IsLinkerGnuLd` and `IsLinkerLLD` into a common ``` enum LinkerFlavour getLinkerFlavor(); ``` but doing this for all possible configs seemed like a can of worms I'd rather not open. > GNU ld is almost ubiquitous on Linux and is almost always available at > /usr/bin/ld (with very few distributions using others linkers by default or > providing an option). > > Detecting linker to affect driver decisions is we Linux are very wary of. We > are nervous even trying to do some stuff only related to lld. I saw: that code is only used on Darwin, it seems, and I'd like to avoid touching that. > We likely don't want this function to be in CommonArgs to lure other > contributors to use. Apart from the move to `Solaris.h`, I've also moved it into the `solaris` namespace to make things completely obvious. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D85309: [Driver] Support GNU ld on Solaris
MaskRay added inline comments. Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:305 +bool tools::isLinkerGnuLd(const ToolChain , const ArgList ) { + // Only used if targetting Solaris. I suppose that this should be in a Solaris specific file to indicate that it's not for other systems. GNU ld is almost ubiquitous on Linux and is almost always available at /usr/bin/ld (with very few distributions using others linkers by default or providing an option). Detecting linker to affect driver decisions is we Linux are very wary of. We are nervous even trying to do some stuff only related to lld. We likely don't want this function to be in CommonArgs to lure other contributors to use. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D85309: [Driver] Support GNU ld on Solaris
ro updated this revision to Diff 554711. ro retitled this revision from "[WIP][clang][Driver] Support GNU ld on Solaris" to "[Driver] Support GNU ld on Solaris". ro added a comment. Herald added subscribers: llvm-commits, Sanitizers, Enna1, ormris. Herald added a reviewer: sscalpone. Herald added a reviewer: awarzynski. Herald added projects: Sanitizers, LLVM, Flang, All. This is a major revison of the original WIP patch that should be (close to) ready. Major differences are: - Linker selection is dynamic now: one can switch between Solaris ld and GNU ld at runtime, with the default selectable with `-DCLANG_DEFAULT_LINKER`. - Testcases have been adjusted to test both variants in case there are differences. - The `compiler-rt/cmake/config-ix.cmake` and `llvm/cmake/modules/AddLLVM.cmake` changes to restrict the tests to Solaris ld are necessary because GNU accepts unknown `-z` options, but warns every time they are used, creating a lot of noise. Since there seems to be no way to check for those warnings in `llvm_check_compiler_linker_flag` or `llvm_check_compiler_linker_flag`, I restrict the cmake tests to Solaris ld in the first place. - The changes to `clang/test/Driver/hip-link-bundle-archive.hip` and `flang/test/Driver/linker-flags.f90` are required to handle the `-DCLANG_DEFAULT_LINKER=gld` case: when this is passed to `cmake`, the `WebAssembly.cpp` `getLinkerPath` returns `/usr/bin/gld` instead of the expected `link`. - `compiler-rt/test/asan/TestCases/global-location-nodebug.cpp` needs to enforce the Solaris ld, otherwise the test would `XPASS` with GNU ld which has the `-S` semantics expected by the test. Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11` with both `-DCLANG_DEFAULT_LINKER=gld` and the default, and `x86_64-pc-linux-gnu`. No regressions in either case. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85309/new/ https://reviews.llvm.org/D85309 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CommonArgs.h clang/lib/Driver/ToolChains/Solaris.cpp clang/lib/Driver/ToolChains/Solaris.h clang/test/Driver/hip-link-bundle-archive.hip clang/test/Driver/solaris-ld-sanitizer.c clang/test/Driver/solaris-ld.c compiler-rt/cmake/config-ix.cmake compiler-rt/test/asan/TestCases/global-location-nodebug.cpp flang/test/Driver/linker-flags.f90 llvm/cmake/modules/AddLLVM.cmake Index: llvm/cmake/modules/AddLLVM.cmake === --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -282,9 +282,9 @@ # ld64's implementation of -dead_strip breaks tools that use plugins. set_property(TARGET ${target_name} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-dead_strip") - elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD) # Support for ld -z discard-unused=sections was only added in -# Solaris 11.4. +# Solaris 11.4. GNU ld ignores it, but warns every time. include(LLVMCheckLinkerFlag) llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED) if (LINKER_SUPPORTS_Z_DISCARD_UNUSED) @@ -1288,7 +1288,10 @@ # the size of the exported symbol table, but on other platforms we can do # it without any trouble. set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) -if (APPLE) +# CMake doesn't set CMAKE_EXE_EXPORTS_${lang}_FLAG on Solaris, so +# ENABLE_EXPORTS has no effect. While Solaris ld defaults to -rdynamic +# behaviour, GNU ld needs it. +if (APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "SunOS") set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -rdynamic") endif() Index: flang/test/Driver/linker-flags.f90 === --- flang/test/Driver/linker-flags.f90 +++ flang/test/Driver/linker-flags.f90 @@ -10,7 +10,7 @@ ! 'oldnames' on Windows, but they are not needed when compiling ! Fortran code and they might bring in additional dependencies. ! Make sure they're not added. -! RUN: %flang -### -target aarch64-windows-msvc %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames +! RUN: %flang -### -target aarch64-windows-msvc -fuse-ld= %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,MSVC --implicit-check-not libcmt --implicit-check-not oldnames ! Compiler invocation to generate the object file ! CHECK-LABEL: {{.*}} "-emit-obj" Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp === --- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp +++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp @@