Fix compiling with -stdlib=libc++

This commit is contained in:
Tom Stellard 2019-02-08 17:47:13 +00:00
parent 81de65ab87
commit d41e350538
4 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,50 @@
From 09ae3ef5710a89505318ec721c65b6c838147276 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar@redhat.com>
Date: Thu, 7 Feb 2019 21:05:37 -0800
Subject: [PATCH] ToolChain: Add -lgcc_s to the linker flags when using libc++
The libc++ build for Fedora does not include an implementation of
libunwind, so we need to explicitly link against something that
provides this implementation.
---
clang/lib/Driver/ToolChain.cpp | 1 +
clang/test/Driver/netbsd.cpp | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 88a627e..cb99844 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -767,6 +767,7 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
switch (Type) {
case ToolChain::CST_Libcxx:
CmdArgs.push_back("-lc++");
+ CmdArgs.push_back("-lgcc_s");
break;
case ToolChain::CST_Libstdcxx:
diff --git a/test/Driver/netbsd.cpp b/test/Driver/netbsd.cpp
index 4af7d83..ff18c62 100644
--- a/test/Driver/netbsd.cpp
+++ b/test/Driver/netbsd.cpp
@@ -131,7 +131,7 @@
// ARM-7: clang{{.*}}" "-cc1" "-triple" "armv5e-unknown-netbsd7.0.0-eabi"
// ARM-7: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
// ARM-7: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}eabi{{/|\\\\}}crti.o"
-// ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++" "-lm" "-lc"
+// ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++" "-lgcc_s" "-lm" "-lc"
// ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
// AARCH64: clang{{.*}}" "-cc1" "-triple" "aarch64-unknown-netbsd"
@@ -250,7 +250,7 @@
// S-ARM-7: clang{{.*}}" "-cc1" "-triple" "armv5e-unknown-netbsd7.0.0-eabi"
// S-ARM-7: ld{{.*}}" "--eh-frame-hdr" "-Bstatic"
// S-ARM-7: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}eabi{{/|\\\\}}crti.o"
-// S-ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++" "-lm" "-lc"
+// S-ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++" "-lgcc_s" "-lm" "-lc"
// S-ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
// S-AARCH64: clang{{.*}}" "-cc1" "-triple" "aarch64-unknown-netbsd"
--
1.8.3.1

View File

@ -61,7 +61,7 @@
Name: %pkg_name Name: %pkg_name
Version: %{maj_ver}.%{min_ver}.%{patch_ver} Version: %{maj_ver}.%{min_ver}.%{patch_ver}
Release: 0.2%{?rc_ver:.rc%{rc_ver}}%{?dist} Release: 0.3%{?rc_ver:.rc%{rc_ver}}%{?dist}
Summary: A C language family front-end for LLVM Summary: A C language family front-end for LLVM
License: NCSA License: NCSA
@ -74,6 +74,7 @@ Source1: http://%{?rc_ver:pre}releases.llvm.org/%{version}/%{?rc_ver:rc%{rc_ver}
Patch4: 0002-gtest-reorg.patch Patch4: 0002-gtest-reorg.patch
Patch9: 0001-Fix-uninitialized-value-in-ABIArgInfo.patch Patch9: 0001-Fix-uninitialized-value-in-ABIArgInfo.patch
Patch10: 0001-Workaround-GCC-9-bug-when-handling-bitfields.patch Patch10: 0001-Workaround-GCC-9-bug-when-handling-bitfields.patch
Patch11: 0001-ToolChain-Add-lgcc_s-to-the-linker-flags-when-using-.patch
BuildRequires: gcc BuildRequires: gcc
BuildRequires: gcc-c++ BuildRequires: gcc-c++
@ -212,6 +213,7 @@ pathfix.py -i %{__python3} -pn \
%patch4 -p1 -b .gtest %patch4 -p1 -b .gtest
%patch9 -p1 -b .abi-arginfo %patch9 -p1 -b .abi-arginfo
%patch10 -p1 -b .bitfields %patch10 -p1 -b .bitfields
%patch11 -p1 -b .libcxx-fix
mv ../%{clang_tools_srcdir} tools/extra mv ../%{clang_tools_srcdir} tools/extra
@ -414,6 +416,9 @@ false
%endif %endif
%changelog %changelog
* Mon Feb 25 2019 tstellar@redhat.com - 8.0.0-0.3.rc2
- Fix compiling with -stdlib=libc++
* Thu Feb 21 2019 sguelton@redhat.com - 8.0.0-0.2.rc2 * Thu Feb 21 2019 sguelton@redhat.com - 8.0.0-0.2.rc2
- 8.0.0 Release candidate 2 - 8.0.0 Release candidate 2

29
tests/llvm-toolchain/runtest.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
# Tests for using a full LLVM toolchain: clang + compiler-rt + libcxx + lld
set -ex pipefail
# Test compile a C program.
cat << EOF | \
clang -fuse-ld=lld -rtlib=compiler-rt -x c - && \
./a.out | grep 'Hello World'
#include<stdio.h>
int main(int argc, char **argv) {
printf("Hello World\n");
return 0;
}
EOF
# Test compile a C++ program.
cat << EOF | \
clang++ -x c++ -fuse-ld=lld -rtlib=compiler-rt -stdlib=libc++ - && \
./a.out | grep 'Hello World'
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Hello World\n";
return 0;
}
EOF

View File

@ -8,6 +8,17 @@
- llvm-test-suite - llvm-test-suite
- ninja-build - ninja-build
- gcc-x86_64-linux-gnu - gcc-x86_64-linux-gnu
# FIXME: It would be nice if we could only install dependencies for a
# single test rather than installing dependencies for all tests. This
# will help us catch bugs with implicit package dependencies e.g.
# package A depends on package B but does not have an explicit Requires.
# These are required for the llvm-toolchain test:
- clang
- lld
- compiler-rt
- libcxx-devel
- glibc-devel
- gcc
tests: tests:
- rhbz#482491: - rhbz#482491:
dir: ./ dir: ./
@ -16,3 +27,4 @@
- llvm-abi-test-suite - llvm-abi-test-suite
- rhbz_1657544 - rhbz_1657544
- rhbz_1647130 - rhbz_1647130
- llvm-toolchain