Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[clang] Add spec for clang and support for SailfishOS gcc toolchain. …
…Contributes to JB#50500
  • Loading branch information
mlehtima committed Sep 28, 2020
1 parent bc653de commit d47e647
Show file tree
Hide file tree
Showing 4 changed files with 417 additions and 0 deletions.
39 changes: 39 additions & 0 deletions rpm/0001-Make-funwind-tables-the-default-for-all-archs.patch
@@ -0,0 +1,39 @@
From 690373af5a5d50cf115ed6e4d2849bb786f9dc8e Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton@redhat.com>
Date: Tue, 10 Dec 2019 09:18:03 +0000
Subject: [PATCH] Make -funwind-tables the default for all archs

---
clang/lib/Driver/ToolChain.cpp | 2 +-
clang/lib/Driver/ToolChains/Gnu.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index b1fddb0af55..43af40ed0e8 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -244,7 +244,7 @@ std::string ToolChain::getInputFilename(const InputInfo &Input) const {
}

bool ToolChain::IsUnwindTablesDefault(const ArgList &Args) const {
- return false;
+ return true;
}

Tool *ToolChain::getClang() const {
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 33cdd3585c2..15e82be8f3a 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2535,7 +2535,7 @@ void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
}

bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const {
- return getArch() == llvm::Triple::x86_64;
+ return true;
}

bool Generic_GCC::isPICDefault() const {
--
2.20.1

@@ -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/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 88a627e..cb99844 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/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/clang/test/Driver/netbsd.cpp b/clang/test/Driver/netbsd.cpp
index 4af7d83..ff18c62 100644
--- a/clang/test/Driver/netbsd.cpp
+++ b/clang/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

105 changes: 105 additions & 0 deletions rpm/clang-sailfishos-toolchain.patch
@@ -0,0 +1,105 @@
diff --git a/clang/include/clang/Driver/Distro.h b/clang/include/clang/Driver/Distro.h
index 67dc764fb7d..2ae6c555515 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -41,6 +41,7 @@ public:
Fedora,
Gentoo,
OpenSUSE,
+ Sailfish,
UbuntuHardy,
UbuntuIntrepid,
UbuntuJaunty,
@@ -117,6 +118,10 @@ public:
return DistroVal >= DebianLenny && DistroVal <= DebianBullseye;
}

+ bool IsSailfish() const {
+ return DistroVal == Sailfish;
+ }
+
bool IsUbuntu() const {
return DistroVal >= UbuntuHardy && DistroVal <= UbuntuEoan;
}
diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index f2a3074d1e7..b9971b63a81 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -145,6 +145,9 @@ static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) {
if (VFS.exists("/etc/gentoo-release"))
return Distro::Gentoo;

+ if (VFS.exists("/etc/sailfish-release"))
+ return Distro::Sailfish;
+
return Distro::UnknownDistro;
}

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 33cdd3585c2..e1890849100 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1927,7 +1927,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
static const char *const AArch64Triples[] = {
"aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
- "aarch64-suse-linux", "aarch64-linux-android"};
+ "aarch64-suse-linux", "aarch64-linux-android", "aarch64-meego-linux-gnu"};
static const char *const AArch64beLibDirs[] = {"/lib"};
static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
"aarch64_be-linux-gnu"};
@@ -1937,6 +1937,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
"arm-linux-androideabi"};
static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf",
"armv7hl-redhat-linux-gnueabi",
+ "armv7hl-meego-linux-gnueabi",
"armv6hl-suse-linux-gnueabi",
"armv7hl-suse-linux-gnueabi"};
static const char *const ARMebLibDirs[] = {"/lib"};
@@ -1964,7 +1965,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
"i586-redhat-linux", "i386-redhat-linux", "i586-suse-linux",
"i486-slackware-linux", "i686-montavista-linux", "i586-linux-gnu",
"i686-linux-android", "i386-gnu", "i486-gnu",
- "i586-gnu", "i686-gnu"};
+ "i586-gnu", "i686-gnu", "i486-meego-linux"};

static const char *const MIPSLibDirs[] = {"/lib"};
static const char *const MIPSTriples[] = {
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 7f59bc77f52..9cf648e2c08 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -248,7 +248,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
}

if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() ||
- Triple.isAndroid()) {
+ Triple.isAndroid() || Distro.IsSailfish()) {
ExtraOpts.push_back("-z");
ExtraOpts.push_back("relro");
}
@@ -289,13 +289,13 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
// Hexagon linker/loader does not support .gnu.hash
if (!IsMips && !IsHexagon) {
if (Distro.IsRedhat() || Distro.IsOpenSUSE() || Distro.IsAlpineLinux() ||
- (Distro.IsUbuntu() && Distro >= Distro::UbuntuMaverick) ||
+ (Distro.IsUbuntu() && Distro >= Distro::UbuntuMaverick) || Distro.IsSailfish() ||
(IsAndroid && !Triple.isAndroidVersionLT(23)))
ExtraOpts.push_back("--hash-style=gnu");

if (Distro.IsDebian() || Distro.IsOpenSUSE() ||
Distro == Distro::UbuntuLucid || Distro == Distro::UbuntuJaunty ||
- Distro == Distro::UbuntuKarmic ||
+ Distro == Distro::UbuntuKarmic || Distro.IsSailfish() ||
(IsAndroid && Triple.isAndroidVersionLT(23)))
ExtraOpts.push_back("--hash-style=both");
}
@@ -304,7 +304,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
ExtraOpts.push_back("--build-id");
#endif

- if (IsAndroid || Distro.IsOpenSUSE())
+ if (IsAndroid || Distro.IsOpenSUSE() || Distro.IsSailfish())
ExtraOpts.push_back("--enable-new-dtags");

// The selection of paths to try here is designed to match the patterns which

0 comments on commit d47e647

Please sign in to comment.