Commit Graph

162 Commits

Author SHA1 Message Date
Nico Weber 6ece82e900 Revert "[Driver] Correctly handle static C++ standard library"
This reverts commit 03142c5f67.
Breaks check-asan if system ld doesn't support --push-state, even
if lld was built and is used according to lit's output.
See comments on https://reviews.llvm.org/D110128
2021-09-24 18:44:53 -04:00
Petr Hosek 03142c5f67 [Driver] Correctly handle static C++ standard library
When statically linking C++ standard library, we shouldn't add -Bdynamic
after including the library on the link line because that might override
user settings like -static and -static-pie. Rather, we should surround
the library with --push-state/--pop-state to make sure that -Bstatic
only applies to C++ standard library and nothing else. This has been
supported since GNU ld 2.25 (2014) so backwards compatibility should
no longer be a concern.

Differential Revision: https://reviews.llvm.org/D110128
2021-09-24 00:40:16 -07:00
Petr Hosek 904ca7d2ed Revert "[Driver] Correctly handle static C++ standard library"
This reverts commit 5e28c892d0 as
the linker on the clang-ppc64le-rhel bot doesn't seem to support
--push-state/--pop-state.
2021-09-23 01:13:10 -07:00
Petr Hosek 5e28c892d0 [Driver] Correctly handle static C++ standard library
When statically linking C++ standard library, we shouldn't add -Bdynamic
after including the library on the link line because that might override
user settings like -static and -static-pie. Rather, we should surround
the library with --push-state/--pop-state to make sure that -Bstatic
only applies to C++ standard library and nothing else. This has been
supported since GNU ld 2.25 (2014) so backwards compatibility should
no longer be a concern.

Differential Revision: https://reviews.llvm.org/D110128
2021-09-23 01:00:11 -07:00
Harald van Dijk 1d463c2a38
[Driver] Fix architecture triplets and search paths for Linux x32
Currently, support for the x32 ABI is handled as a multilib to the
x86_64 target only. However, full self-hosting x32 systems treating it
as a separate architecture with its own architecture triplets as well as
search paths exist as well, in Debian's x32 port and elsewhere.

This adds the missing architecture triplets and search paths so that
clang can work as a native compiler on x32, and updates the tests so
that they pass when using an x32 libdir suffix.

Additionally, we would previously also assume that objects from any
x86_64-linux-gnu GCC installation could be used to target x32. This
changes the logic so that only GCC installations that include x32
support are used when targetting x32, meaning x86_64-linux-gnux32 GCC
installations, and x86_64-linux-gnu and i686-linux-gnu GCC installations
that include x32 multilib support.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D52050
2021-04-01 09:47:56 +01:00
Fangrui Song dcaa0293c1 [test] Add UNSUPPORTED: system-windows to linux-ld.c
We should have a test verifying / \ for Windows but have such a long
test specifically for Linux cross compilation suffer from Windows \
is too troublesome.
2021-03-27 16:46:30 -07:00
Fangrui Song 87a9f42fc1 [Driver] Remove an incorrect library path for multilib
This is incorrect (adding a path with unrelated libraries) but benign in practice because previous paths take precedence.
2021-03-27 16:36:21 -07:00
Fangrui Song 19e45696f5 [Driver] Remove an unneeded multiarch library path which ends with ../../..
Neither vanilla nor Debian GCC has the patch, which usually duplicates $sysroot/usr/lib.
2021-03-27 15:46:06 -07:00
Fangrui Song bfbfd83f14 [Driver] Linux.cpp: delete unneeded D.getVFS().exists checks
Not only can this save unneeded filesystem stats, it can make `clang
--sysroot=/path/to/debian-sysroot -c a.cc` work (get `-internal-isystem
$sysroot/usr/include/x86_64-linux-gnu`) even without `lib/x86_64-linux-gnu/`.
This should make thakis happy.
2021-03-24 15:25:36 -07:00
Fangrui Song 72ac988dc7 [test] Delete obsoleted debian_multiarch_tree and ubuntu_13.04_multiarch_tree
They are quite outdated. Delete them to avoid unnecessary test churn.
2021-03-21 15:37:34 -07:00
Fangrui Song 0ad0c476ef [Driver] Gnu.cpp: remove unneeded -L detection hack for -mx32
Removing the hack actually improves our compatibility with gcc -mx32.
2021-03-20 20:12:45 -07:00
Fangrui Song 06d6b1471e [Driver] Gnu.cpp: remove unneeded -L lib/gcc/$triple/$version/../../../$triple
After path resolution, it duplicates a subsequent -L entry. The entry below
(lib/gcc/$triple/$version/../../../../$OSLibDir) usually does not exist (e.g.
Arch Linux; Debian cross gcc). When it exists, it typically just has ld.so (e.g.
Debian native gcc) which cannot cause collision. Removing the -L (similar to
reordering it) is therefore justified.
2021-03-20 18:50:14 -07:00
Fangrui Song dc3b438c8f Revert "Revert "[Driver] Drop obsoleted Ubuntu 11.04 gcc detection""
This reverts commit 243333ef3e.
2021-03-20 09:57:05 -07:00
David Zarzycki 243333ef3e Revert "[Driver] Drop obsoleted Ubuntu 11.04 gcc detection"
This reverts commit bdf39e6b0e.

The change is failing on Fedora 33 (x86-64).
2021-03-20 07:29:01 -04:00
Fangrui Song bdf39e6b0e [Driver] Drop obsoleted Ubuntu 11.04 gcc detection
It has a very broken gcc installation path (usr/lib/i386-linux-gnu/gcc/i686-linux-gnu).
2021-03-19 23:23:28 -07:00
Fangrui Song 28d58d8fe2 [Driver] Stop searching other prefixes once a GCC installation is found in one prefix
so that when --sysroot is specified, the detected GCC installation will not be
overridden by another from /usr which happens to have a larger version.

This behavior is particularly inconvenient when the system has a larger version
GCC while the user wants to try out an older sysroot.

Delete some tests from linux-ld.c which overlap with cross-linux.c
2021-03-19 20:35:59 -07:00
Ryan Prichard a478b0a199 [Android] Default to --rtlib=compiler-rt
By default, the driver uses the compiler-rt builtins and links with
-l:libunwind.a.

Restore the previous behavior by passing --rtlib=libgcc.

Reviewed By: danalbert

Differential Revision: https://reviews.llvm.org/D96404
2021-03-09 18:09:53 -08:00
Petr Hosek 7514f1a312 [Driver] Pass --unwindlib=platform to tests that check unwinder
There are two additional cases that were missed in D98131.

Differential Revision: https://reviews.llvm.org/D98158
2021-03-07 17:28:34 -08:00
Petr Hosek 41476d89b8 [Driver] Pass --unwindlib=platform to tests that check unwinder
This addresses an issue which was revealed by D98022.

Differential Revision: https://reviews.llvm.org/D98131
2021-03-06 21:44:26 -08:00
Nico Weber 1608ba0946 Revert "Disable rosegment for old Android versions."
This reverts commit fae16fc0ee.
Breaks building compiler-rt android runtimes with trunk clang
but older NDK, see discussion on https://reviews.llvm.org/D95166
2021-01-29 11:20:48 -05:00
Dan Albert fae16fc0ee Disable rosegment for old Android versions.
The unwinder used by the crash handler on versions of Android prior to
API 29 did not correctly handle binaries built with rosegment, which is
enabled by default for LLD. Android only supports LLD, so it's not an
issue that this flag is not accepted by other linkers.

Reviewed By: srhines

Differential Revision: https://reviews.llvm.org/D95166
2021-01-26 16:15:45 -08:00
Jinsong Ji b49b8f096c [PowerPC][Clang] Remove QPX support
Clean up QPX code in clang missed in https://reviews.llvm.org/D83915

Reviewed By: #powerpc, steven.zhang

Differential Revision: https://reviews.llvm.org/D92329
2020-12-07 10:15:39 -05:00
John Paul Adrian Glaubitz c2fb114475 [Driver] Enable getOSLibDir() lib32 workaround for SPARC on Linux
This fixes the Builtins-sparc-linux testsuite failures on Linux
SPARC which occur because clang cannot find the 32-bit runtime
libraries when -m32 is passed on the command line. The same
workaround is already being used on X86 and PPC.

Also, switch the CHECK-DEBIAN-SPARC tests to use debian_multiarch_tree
as both sparc and sparc64 are using the MultiArch mechanism on modern Debian
systems the same way as x86_64, powerpc64el and others. Thus, switch the
CHECK-DEBIAN-SPARC32 and CHECK-DEBIAN-SPARC64 tests to use the files from
the debian_multiarch_tree directory for the header and linker path tests.

Finally, rename CHECK-DEBIAN-SPARC32 to CHECK-DEBIAN-SPARC to match the naming
scheme of the Debian MultiArch checks for the other Debian architectures.

Reviewed By: MaskRay, phosek

Differential Revision: https://reviews.llvm.org/D90524
2020-11-23 19:25:36 -08:00
Luís Marques 9816e726e7 [Driver][RISCV] Add RedHat Linux RISC-V triple
Summary: Adds the RedHat Linux triple to the list of 64-bit RISC-V triples.
Without this the gcc libraries wouldn't be found by clang on a redhat/fedora
system, as the search list included `/usr/lib/gcc/riscv64-redhat-linux-gnu`
but the correct path didn't include the `-gnu` suffix.

Reviewers: lenary, asb, dlj
Reviewed By: lenary
Tags: #clang
Differential Revision: https://reviews.llvm.org/D74399
2020-02-14 13:46:26 +00:00
Aaron Puchert 0010ea4224 [Driver] Fix incorrect GNU triplet for PowerPC on SUSE Linux
Summary:
On SUSE distributions for 32-bit PowerPC, gcc is configured
as a 64-bit compiler using the GNU triplet "powerpc64-suse-linux",
but invoked with "-m32" by default. Thus, the correct GNU triplet
for 32-bit PowerPC SUSE distributions is "powerpc64-suse-linux"
and not "powerpc-suse-linux".

Reviewers: jrtc27, nemanjai, glaubitz

Reviewed By: nemanjai

Differential Revision: https://reviews.llvm.org/D55326
2019-11-23 16:00:53 +01:00
Sam Elliott 1fc2a47f0b Add support for openSUSE RISC-V triple
Reviewers: asb

Reviewed By: asb

Subscribers: lenary, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, lebedev.ri, kito-cheng, shiva0217, rogfer01, dexonsmith, rkruppe, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D63497

Patch by Andreas Schwab (schwab)

llvm-svn: 367565
2019-08-01 14:23:56 +00:00
Fangrui Song 0666f9c4e4 [Driver] -static-pie: add -z text
This matches gcc -static-pie. The intention is to prevent dynamic
relocations in read-only segments.

In ld.bfd and gold, -z notext is the default. If text relocations are needed:

* -z notext: allow and emit DF_TEXTREL.
  DF_TEXTREL is not emitted if there is no text relocation.
* -z text: error

In lld, -z text is the default (this change is a no-op).

* -z text: error on text relocations
* -z notext: allow text relocations, and emit DF_TEXTREL no matter whether
  text relocations exist.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D62606

llvm-svn: 362050
2019-05-30 01:55:43 +00:00
Siva Chandra 8692af253c Let -static-pie win if it is specified along with -pie or -static.
Also, disallow specifying -no-pie/-nopie along with -static-pie.

Differential Revision: https://reviews.llvm.org/D59841

llvm-svn: 361312
2019-05-21 21:09:05 +00:00
Petr Hosek b4989294c8 [Driver] Support compiler-rt crtbegin.o/crtend.o for Linux
When compiler-rt is selected as the runtime library for Linux targets
use its crtbegin.o/crtend.o implemenetation rather than platform one
if available.

Differential Revision: https://reviews.llvm.org/D59264

llvm-svn: 359603
2019-04-30 19:35:14 +00:00
Simon Atanasyan 751510cd78 [driver][mips] Check both `gnuabi64` and `gnu` suffixes in `getMultiarchTriple`
In case of N64 ABI toolchain paths migth have `mips-linux-gnuabi64`
or `mips-linux-gnu` directory regardless of selected environment.
Check both variants while detecting a multiarch triple.

Fix for the bug https://bugs.llvm.org/show_bug.cgi?id=41204

llvm-svn: 357506
2019-04-02 18:03:31 +00:00
Dan Albert 50e18a250f [Driver] Use --warn-shared-textrel for Android.
Android does not allow shared text relocations. Enable the linker
warning to detect them by default.

Reviewers: srhines, pirama

Reviewed By: srhines

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D53344

llvm-svn: 357296
2019-03-29 18:34:25 +00:00
Dan Albert 2715b28716 [Driver] Default Android toolchains to noexecstack.
Android does not support executable stacks.

Reviewers: srhines, pirama

Reviewed By: pirama

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D53343

llvm-svn: 357197
2019-03-28 18:08:28 +00:00
Siva Chandra 3988d5c8fa [Clang Driver] Add support for "-static-pie" argument to the Clang driver.
Summary: This change mimics GCC's support for the "-static-pie" argument.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58307

llvm-svn: 354502
2019-02-20 19:07:04 +00:00
Sterling Augustine b6d0f85daf Properly support -shared-libgcc.
This revision was revied in D55016.

llvm-svn: 350900
2019-01-10 22:25:58 +00:00
Peter Smith e75b6d78e0 [ARM][AArch64] Pass through endian flags to assembler and linker.
The big-endian arm32 Linux builds are currently failing when the
-mbig-endian flag is used but the binutils default on the system is little
endian. This also holds when -mlittle-endian is used and the binutils
default is big endian.

The patch always passes through -EL or -BE to the assembler and linker,
taking into account the target and the -mbig-endian and -mlittle-endian
flag.

Fixes pr38770

Differential Revision: https://reviews.llvm.org/D52784

llvm-svn: 344597
2018-10-16 09:21:17 +00:00
Simon Atanasyan db81c7b9c9 [mips] Fix handling of GNUABIN32 environment in a target triple
The `GNUABIN32` environment in a target triple implies using the N32
ABI. This patch adds support for this environment and switches on N32
ABI if necessary.

Patch by Patch by YunQiang Su.

Differential revision: https://reviews.llvm.org/D51464

llvm-svn: 344570
2018-10-15 22:43:23 +00:00
Sid Manning 61471cc090 [Hexagon] Update tests account for non-hardcoded linker name.
Tests should not assume the linker's name, CLANG_DEFAULT_LINKER could
change it.

Differential Revision: https://reviews.llvm.org/D53219

llvm-svn: 344482
2018-10-14 17:51:36 +00:00
Dan Albert e4dd75a9cb [Driver] Default to `-z now` and `-z relro` on Android.
Summary:
RTLD_LAZY is not supported on Android (though failing to use `-z now`
will work since it is assumed by the loader).

RelRO is required.

Reviewers: srhines, pirama

Reviewed By: srhines

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D53117

llvm-svn: 344295
2018-10-11 20:57:54 +00:00
Dan Albert 99ac6c8e89 [Driver] Fix --hash-style choice for Android.
Summary:
Android supports GNU style hashes as of Marshmallow, so we should be
generating both styles for pre-M targets and GNU hashes for newer
targets.

Reviewers: srhines, pirama

Reviewed By: srhines

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D53118

llvm-svn: 344293
2018-10-11 20:39:32 +00:00
Peter Smith d8e7ed6457 [Aarch64] Fix linker emulation for Aarch64 big endian
This patch fixes target linker emulation for aarch64 big endian.
aarch64_be_linux is not recognized by gnu ld. The equivalent emulation
mode supported by gnu ld is aarch64linuxb.

Patch by: Bharathi Seshadri

Reviewed by: Peter Smith

Differential Revision: https://reviews.llvm.org/D42930

llvm-svn: 341312
2018-09-03 12:36:32 +00:00
Sterling Augustine 1c04e1f552 Refactor Addlibgcc to make the when and what logic more straightfoward.
Add Android tests.

llvm-svn: 341231
2018-08-31 17:59:03 +00:00
Douglas Yung 11982cd7db Change %clang++ to %clangxx in test run line as it was expanding to clang.exe++ on Windows.
llvm-svn: 341106
2018-08-30 19:52:57 +00:00
Sterling Augustine 5acd669330 Test the cross-product of how libgcc-related arguments are passed to the linker.
llvm-svn: 341083
2018-08-30 16:37:06 +00:00
Karl-Johan Karlsson d51f702f22 Fix clash of gcc toolchains in driver regression tests
For some regression tests the path to the right toolchain is specified
using the -sysroot switch. However, if clang was configured with a
custom gcc toolchain (either by using GCC_INSTALL_PREFIX in cmake or the
equivalent configure command), the path to the custom gcc toolchain path
takes precedence to the one specified by sysroot. This causes several
regression tests to fail as they will be using an unexpected path. This
patch fixes this issue by adding --gcc-toolchain='' to all tests that
rely on that. The empty string causes the driver to pick the path from
sysroot instead.

This patch contain the same kind of fixes as done in rC225182

llvm-svn: 339112
2018-08-07 08:10:33 +00:00
Petr Hosek 78c20a8563 [OpenEmbedded] Explicitly specify -rtlib in tests
Tests added in r338294 implicitly assume that libgcc is the runtime library,
but that's not the case when the user configures Clang to use compiler-rt in
which case these tests will break. Explicitly request libgcc when invoking
clang in these tests to avoid that.

Differential Revision: https://reviews.llvm.org/D50123

llvm-svn: 338482
2018-08-01 03:30:06 +00:00
Mandeep Singh Grang e9ddc44a60 [OpenEmbedded] Fix lib paths for OpenEmbedded targets
Summary:
The lib paths are not correctly picked up for OpenEmbedded sysroots (like arm-oe-linux-gnueabi) for 2 reasons:

1. OpenEmbedded sysroots are of the form <sysroot>/usr/lib/<triple>/x.y.z. This form is handled in clang but only for Freescale vendor.

2. 64-bit OpenEmbedded sysroots may not have a /usr/lib dir. So they cannot find /usr/lib64 as it is referenced as /usr/lib/../lib64 in clang.

This is a follow-up to the llvm patch: D48861

Reviewers: dlj, rengolin, fedor.sergeev, javed.absar, hfinkel, rsmith

Reviewed By: rsmith

Subscribers: rsmith, kristof.beyls, cfe-commits

Differential Revision: https://reviews.llvm.org/D48862

llvm-svn: 338294
2018-07-30 19:44:13 +00:00
Jiading Gai 4a2879bd5a For x86_64, gcc 7.2 under Amazon Linux AMI sets its path to x86_64-amazon-linux.
gcc 7.2 under Amazon Linux AMI sets its paths to x86_64-amazon-linux. Adding 
this triple to the list of search, plus a test case to cover this.

The patch fixes the following bug reported in bugzilla:

https://bugs.llvm.org/show_bug.cgi?id=35992

Reviewers: echristo

Differential Revision: https://reviews.llvm.org/D46230

llvm-svn: 337811
2018-07-24 06:07:22 +00:00
Tom Stellard 345a22d0ba Driver: Add an explicit target to testcase from r336037
llvm-svn: 336039
2018-06-30 03:50:10 +00:00
Tom Stellard c5fe10f365 Driver: Don't mix system tools with devtoolset tools on RHEL
Summary:
On RHEL, devtoolset provides a more up-to-date toolchain than the base
install, and we want to make sure all the tools use are from the same
toolchain.

Reviewers: rsmith, bruno

Reviewed By: bruno

Subscribers: bruno, cfe-commits

Differential Revision: https://reviews.llvm.org/D34848

llvm-svn: 336037
2018-06-30 02:55:54 +00:00
Petr Hosek 887f26d470 Support for multiarch runtimes layout
This change adds a support for multiarch style runtimes layout, so in
addition to the existing layout where runtimes get installed to:

lib/clang/$version/lib/$os

Clang now allows runtimes to be installed to:

lib/clang/$version/$target/lib

This also includes libc++, libc++abi and libunwind; today those are
assumed to be in Clang library directory built for host, with the
new layout it is possible to install libc++, libc++abi and libunwind
into the runtime directory built for different targets.

The use of new layout is enabled by setting the
LLVM_ENABLE_RUNTIME_TARGET_DIR CMake variable and is supported by both
projects and runtimes layouts. The runtimes CMake build has been further
modified to use the new layout when building runtimes for multiple
targets.

Differential Revision: https://reviews.llvm.org/D45604

llvm-svn: 335809
2018-06-28 03:11:52 +00:00