[compiler-rt] Build it with gcc

Vadim vadimcn at gmail.com
Tue Feb 4 18:33:27 PST 2014


Hi,
I am trying to use compiler-rt as a replacement for libgcc in a compiler
for the Rust language.   In the process I came up with as set of patches,
which I hope will be useful to other people as well.   Specifically, these
patches:
- enable building compiler-rt with GCC (because we don't want to require
installation or building of clang),
- enable building it for an arbitrary LLVM target triple (just the runtime
part for now, excluding sanitizers),
- enable building it on Windows with mingw (assembly syntax variations),
- enable building it for arm-linux-androideabi (assembly syntax variations).

Vadim

----------

>From 5d0ef64e0e35779af23c9ebedc2692f16f7e2e6d Mon Sep 17 00:00:00 2001
From: Vadim Chugunov <vadimcn at gmail.com>
Date: Sun, 2 Feb 2014 22:43:10 -0800
Subject: [PATCH 1/5] Windows does not have the ".const" directive and the
 function type must be declared differently.

---
 lib/assembly.h           | 4 ++++
 lib/i386/floatdidf.S     | 4 +---
 lib/i386/floatundidf.S   | 4 +---
 lib/i386/floatundisf.S   | 8 ++++----
 lib/i386/floatundixf.S   | 4 +---
 lib/x86_64/floatundidf.S | 4 +---
 lib/x86_64/floatundixf.S | 6 ++----
 7 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/lib/assembly.h b/lib/assembly.h
index 1a9f79c..b950d06 100644
--- a/lib/assembly.h
+++ b/lib/assembly.h
@@ -27,12 +27,16 @@
 #define LOCAL_LABEL(name) L_##name
 #define FILE_LEVEL_DIRECTIVE  .subsections_via_symbols
 #define SYMBOL_IS_FUNC(name)
+#define CONST_SECTION .const
 #else
 #define HIDDEN_DIRECTIVE .hidden
 #define LOCAL_LABEL(name) .L_##name
 #define FILE_LEVEL_DIRECTIVE
+#define CONST_SECTION .text
 #  if defined(__arm__)
 #  define SYMBOL_IS_FUNC(name) .type name, %function
+#  elif __WIN32__
+#  define SYMBOL_IS_FUNC(name) .def name; .scl 3; .type 32; .endef
 #  else
 #  define SYMBOL_IS_FUNC(name) .type name, @function
 #  endif
diff --git a/lib/i386/floatdidf.S b/lib/i386/floatdidf.S
index 4936088..b0fb7c8 100644
--- a/lib/i386/floatdidf.S
+++ b/lib/i386/floatdidf.S
@@ -7,9 +7,7 @@

 #ifdef __i386__

-#ifndef __ELF__
-.const
-#endif
+CONST_SECTION
 .align 4
 twop52: .quad 0x4330000000000000
 twop32: .quad 0x41f0000000000000
diff --git a/lib/i386/floatundidf.S b/lib/i386/floatundidf.S
index 5b8787b..b2dcf3a 100644
--- a/lib/i386/floatundidf.S
+++ b/lib/i386/floatundidf.S
@@ -17,9 +17,7 @@

 #ifdef __i386__

-#ifndef __ELF__
-.const
-#endif
+CONST_SECTION
 .align 4
 twop52: .quad 0x4330000000000000
 twop84_plus_twop52:
diff --git a/lib/i386/floatundisf.S b/lib/i386/floatundisf.S
index 2253021..3d29a62 100644
--- a/lib/i386/floatundisf.S
+++ b/lib/i386/floatundisf.S
@@ -18,7 +18,7 @@

 #ifdef __i386__

-.const
+CONST_SECTION
 .align 3

         .quad    0x43f0000000000000
@@ -52,8 +52,8 @@ END_COMPILERRT_FUNCTION(__floatundisf)

 #ifdef __i386__

-#ifndef __ELF__
-.const
+CONST_SECTION
+#if !defined(__ELF__) && !defined(__WIN32__)
 .align 3
 #else
 .align 8
@@ -74,7 +74,7 @@ DEFINE_COMPILERRT_FUNCTION(__floatundisf)
     movd        8(%esp),        %xmm1
     movd        4(%esp),        %xmm0
     punpckldq    %xmm1,            %xmm0
-
+
     calll        0f
 0:    popl        %ecx
     shrl        %eax                    // high 31 bits of input as sint32
diff --git a/lib/i386/floatundixf.S b/lib/i386/floatundixf.S
index b728d06..63ef3aa 100644
--- a/lib/i386/floatundixf.S
+++ b/lib/i386/floatundixf.S
@@ -7,9 +7,7 @@

 #ifdef __i386__

-#ifndef __ELF__
-.const
-#endif
+CONST_SECTION
 .align 4
 twop52: .quad 0x4330000000000000
 twop84_plus_twop52_neg:
diff --git a/lib/x86_64/floatundidf.S b/lib/x86_64/floatundidf.S
index 1df3d74..7975e1a 100644
--- a/lib/x86_64/floatundidf.S
+++ b/lib/x86_64/floatundidf.S
@@ -17,9 +17,7 @@

 #ifdef __x86_64__

-#ifndef __ELF__
-.const
-#endif
+CONST_SECTION
 .align 4
 twop52: .quad 0x4330000000000000
 twop84_plus_twop52:
diff --git a/lib/x86_64/floatundixf.S b/lib/x86_64/floatundixf.S
index b05954a..037c2a7 100644
--- a/lib/x86_64/floatundixf.S
+++ b/lib/x86_64/floatundixf.S
@@ -7,9 +7,7 @@

 #ifdef __x86_64__

-#ifndef __ELF__
-.const
-#endif
+CONST_SECTION
 .align 4
 twop64: .quad 0x43f0000000000000

@@ -35,7 +33,7 @@ END_COMPILERRT_FUNCTION(__floatundixf)

 #ifdef __x86_64__

-.const
+CONST_SECTION
 .align 4
 twop52: .quad 0x4330000000000000
 twop84_plus_twop52_neg:
-- 
1.8.5.2.msysgit.0

>From deb3972b20fcb0679122730cdd752dc0a4519003 Mon Sep 17 00:00:00 2001
From: Vadim Chugunov <vadimcn at gmail.com>
Date: Mon, 3 Feb 2014 18:43:13 -0800
Subject: [PATCH 2/5] Only Macs use .subsections_via_symbols

---
 lib/arm/restore_vfp_d8_d15_regs.S | 4 ++--
 lib/arm/save_vfp_d8_d15_regs.S    | 4 ++--
 lib/arm/switch16.S                | 4 ++--
 lib/arm/switch32.S                | 4 ++--
 lib/arm/switch8.S                 | 4 ++--
 lib/arm/switchu8.S                | 4 ++--
 lib/arm/sync_synchronize.S        | 4 ++--
 7 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/arm/restore_vfp_d8_d15_regs.S
b/lib/arm/restore_vfp_d8_d15_regs.S
index 5d55474..dc57655 100644
--- a/lib/arm/restore_vfp_d8_d15_regs.S
+++ b/lib/arm/restore_vfp_d8_d15_regs.S
@@ -31,5 +31,5 @@
DEFINE_COMPILERRT_PRIVATE_FUNCTION(__restore_vfp_d8_d15_regs)
     bx      lr                      // return to prolog
 END_COMPILERRT_FUNCTION(__restore_vfp_d8_d15_regs)

-    // tell linker it can break up file at label boundaries
-    .subsections_via_symbols
+// tell linker it can break up file at label boundaries
+FILE_LEVEL_DIRECTIVE
diff --git a/lib/arm/save_vfp_d8_d15_regs.S b/lib/arm/save_vfp_d8_d15_regs.S
index 4be3ff3..233772b 100644
--- a/lib/arm/save_vfp_d8_d15_regs.S
+++ b/lib/arm/save_vfp_d8_d15_regs.S
@@ -31,5 +31,5 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(__save_vfp_d8_d15_regs)
     bx      lr                      // return to prolog
 END_COMPILERRT_FUNCTION(__save_vfp_d8_d15_regs)

-    // tell linker it can break up file at label boundaries
-    .subsections_via_symbols
+// tell linker it can break up file at label boundaries
+FILE_LEVEL_DIRECTIVE
diff --git a/lib/arm/switch16.S b/lib/arm/switch16.S
index 0dedc59..e0ca444 100644
--- a/lib/arm/switch16.S
+++ b/lib/arm/switch16.S
@@ -42,5 +42,5 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch16)
     bx      ip                      // jump to computed label
 END_COMPILERRT_FUNCTION(__switch16)

-    // tell linker it can break up file at label boundaries
-    .subsections_via_symbols
+// tell linker it can break up file at label boundaries
+FILE_LEVEL_DIRECTIVE
diff --git a/lib/arm/switch32.S b/lib/arm/switch32.S
index 64d558e..54812af 100644
--- a/lib/arm/switch32.S
+++ b/lib/arm/switch32.S
@@ -42,6 +42,6 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch32)
     bx      ip                       // jump to computed label
 END_COMPILERRT_FUNCTION(__switch32)

-    // tell linker it can break up file at label boundaries
-    .subsections_via_symbols
+// tell linker it can break up file at label boundaries
+FILE_LEVEL_DIRECTIVE

diff --git a/lib/arm/switch8.S b/lib/arm/switch8.S
index b500884..e0d089d 100644
--- a/lib/arm/switch8.S
+++ b/lib/arm/switch8.S
@@ -40,6 +40,6 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch8)
     bx      ip                      // jump to computed label
 END_COMPILERRT_FUNCTION(__switch8)

-    // tell linker it can break up file at label boundaries
-    .subsections_via_symbols
+// tell linker it can break up file at label boundaries
+FILE_LEVEL_DIRECTIVE

diff --git a/lib/arm/switchu8.S b/lib/arm/switchu8.S
index 488d4e7..daaf605 100644
--- a/lib/arm/switchu8.S
+++ b/lib/arm/switchu8.S
@@ -40,6 +40,6 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switchu8)
     bx      ip                      // jump to computed label
 END_COMPILERRT_FUNCTION(__switchu8)

-    // tell linker it can break up file at label boundaries
-    .subsections_via_symbols
+// tell linker it can break up file at label boundaries
+FILE_LEVEL_DIRECTIVE

diff --git a/lib/arm/sync_synchronize.S b/lib/arm/sync_synchronize.S
index aa18f04..96971cd 100644
--- a/lib/arm/sync_synchronize.S
+++ b/lib/arm/sync_synchronize.S
@@ -29,7 +29,7 @@ DEFINE_COMPILERRT_PRIVATE_FUNCTION(__sync_synchronize)
     ldmfd    sp!, {r7, pc}
 END_COMPILERRT_FUNCTION(__sync_synchronize)

-    // tell linker it can break up file at label boundaries
-    .subsections_via_symbols
+// tell linker it can break up file at label boundaries
+FILE_LEVEL_DIRECTIVE

 #endif
-- 
1.8.5.2.msysgit.0

>From 47f3beebb666dcbc3c0e7653a7a808dffd4fa066 Mon Sep 17 00:00:00 2001
From: Vadim Chugunov <vadimcn at gmail.com>
Date: Sun, 2 Feb 2014 22:44:28 -0800
Subject: [PATCH 3/5] -fPIC switch does not apply on Windows.

---
 make/config.mk                | 4 ++--
 make/platform/clang_darwin.mk | 2 +-
 make/platform/clang_linux.mk  | 2 +-
 make/platform/darwin_bni.mk   | 2 +-
 make/platform/darwin_fat.mk   | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/make/config.mk b/make/config.mk
index 2838b60..9364c74 100644
--- a/make/config.mk
+++ b/make/config.mk
@@ -44,6 +44,6 @@ endif
 ###
 # Common compiler options
 COMMON_INCLUDES=-I${ProjSrcRoot}/lib -I${ProjSrcRoot}/include
-COMMON_CXXFLAGS=-fno-exceptions -fPIC -funwind-tables $(COMMON_INCLUDES)
-COMMON_CFLAGS=-fPIC $(COMMON_INCLUDES)
+COMMON_CXXFLAGS=-fno-exceptions -funwind-tables $(COMMON_INCLUDES)
+COMMON_CFLAGS=$(COMMON_INCLUDES)
 COMMON_ASMFLAGS=$(COMMON_INCLUDES)
diff --git a/make/platform/clang_darwin.mk b/make/platform/clang_darwin.mk
index 3dd18e1..534fae9 100644
--- a/make/platform/clang_darwin.mk
+++ b/make/platform/clang_darwin.mk
@@ -136,7 +136,7 @@ endif
 override CC := $(subst -arch ,-arch_,$(CC))
 override CC := $(patsubst -arch_%,,$(CC))

-CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
+CFLAGS := -fPIC -Wall -Werror -O3 -fomit-frame-pointer

 # Always set deployment target arguments for every build, these libraries
should
 # never depend on the environmental overrides. We simply set them to
minimum
diff --git a/make/platform/clang_linux.mk b/make/platform/clang_linux.mk
index fe39a2d..b6cbf32 100644
--- a/make/platform/clang_linux.mk
+++ b/make/platform/clang_linux.mk
@@ -85,7 +85,7 @@ endif

 ###

-CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
+CFLAGS := -fPIC -Wall -Werror -O3 -fomit-frame-pointer
 SANITIZER_CFLAGS := -fPIE -fno-builtin -gline-tables-only

 CFLAGS.full-i386 := $(CFLAGS) -m32
diff --git a/make/platform/darwin_bni.mk b/make/platform/darwin_bni.mk
index 03e8d29..aa1319b 100644
--- a/make/platform/darwin_bni.mk
+++ b/make/platform/darwin_bni.mk
@@ -29,7 +29,7 @@ ifneq (,$(SDKROOT))
     DEPLOYMENT_FLAGS += -isysroot $(SDKROOT)
 endif

-CFLAGS := -Wall -Os -fomit-frame-pointer -g $(DEPLOYMENT_FLAGS)
+CFLAGS := -fPIC -Wall -Os -fomit-frame-pointer -g $(DEPLOYMENT_FLAGS)
 CFLAGS.Static := $(CFLAGS) -static
 DYLIB_FLAGS := $(DEPLOYMENT_FLAGS) \
         -Xarch_arm -Wl,-alias_list,$(SRCROOT)/lib/arm/softfloat-alias.list
diff --git a/make/platform/darwin_fat.mk b/make/platform/darwin_fat.mk
index 54936a3..eaf55ff 100644
--- a/make/platform/darwin_fat.mk
+++ b/make/platform/darwin_fat.mk
@@ -39,7 +39,7 @@ UniversalArchs := i386 x86_64

 CC := clang

-CFLAGS := -Wall -Werror
+CFLAGS := -fPIC -Wall -Werror
 CFLAGS.Debug := $(CFLAGS) -g
 CFLAGS.Release := $(CFLAGS) -O3 -fomit-frame-pointer
 CFLAGS.Profile := $(CFLAGS) -pg -g
-- 
1.8.5.2.msysgit.0

>From 4036b71dc47ad734ba1130e54b07f00958841b11 Mon Sep 17 00:00:00 2001
From: Vadim Chugunov <vadimcn at gmail.com>
Date: Mon, 3 Feb 2014 18:54:25 -0800
Subject: [PATCH 4/5] This file doesn't need to be executable.

---
 lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100755 => 100644
lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc

diff --git a/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
b/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
old mode 100755
new mode 100644
-- 
1.8.5.2.msysgit.0

>From d4606f1818dd8dfeaa3e509cd1cbac4482c3513e Mon Sep 17 00:00:00 2001
From: Vadim Chugunov <vadimcn at gmail.com>
Date: Mon, 3 Feb 2014 00:03:01 -0800
Subject: [PATCH 5/5] Enable building compiler-rt for a specific LLVM triple
 with GCC.

---
 make/platform/triple.mk | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 make/platform/triple.mk

diff --git a/make/platform/triple.mk b/make/platform/triple.mk
new file mode 100644
index 0000000..6a3eb99
--- /dev/null
+++ b/make/platform/triple.mk
@@ -0,0 +1,27 @@
+# This "platform" file is intended for building compiler-rt using gcc.
+# The actual target platform is selected by setting the TargetTriple
variable to the corresponding LLVM triple.
+
+Description := Static runtime libraries for platforms selected by
'TargetTriple'
+
+# Provide defaults for the required vars
+ifndef CC
+    CC := gcc
+endif
+ifndef CFLAGS
+    CFLAGS := -Wall -O3
+endif
+
+Configs := runtime
+
+Arch := $(word 1,$(subst -, ,$(TargetTriple)))
+ifeq ($(Arch),i686)
+    Arch := i386
+else ifeq ($(Arch),arm)
+    Arch := armv7
+endif
+
+# Filter out stuff that gcc cannot compile (these are only needed for
clang-generated code anywasys).
+CommonFunctions_gcc := $(filter-out atomic
enable_execute_stack,$(CommonFunctions))
+
+FUNCTIONS.runtime := $(CommonFunctions_gcc) $(value ArchFunctions.$(Arch))
+
-- 
1.8.5.2.msysgit.0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140204/afa36868/attachment.html>


More information about the llvm-commits mailing list