Add a VISIBILITY_HIDDEN option, which can be used to make all compiler-rt function definitions hidden/private extern.
llvm-svn: 93790
diff --git a/compiler-rt/Makefile b/compiler-rt/Makefile
index 5a6f017..79149e3 100644
--- a/compiler-rt/Makefile
+++ b/compiler-rt/Makefile
@@ -205,19 +205,20 @@
$(call Set,Tmp.CC,$(strip \
$(call GetCNAVar,CC,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
$(call Set,Tmp.CFLAGS,$(strip \
+ $(if $(call IsDefined,$(Tmp.Key).UniversalArchs),-arch $(Tmp.Arch),)\
+ $(if $(call streq,$($(Tmp.Key).VISIBILITY_HIDDEN),1),\
+ -fvisibility=hidden -DVISIBILITY_HIDDEN,)\
$(call GetCNAVar,CFLAGS,$(Tmp.Key),$(Tmp.Config),$(Tmp.Arch))))
-$(call Set,Tmp.ArchFlag,$(strip \
- $(if $(call IsDefined,$(Tmp.Key).UniversalArchs),-arch $(Tmp.Arch),)))
$(Tmp.ObjPath)/%.o: $(Tmp.SrcPath)/%.s $(Tmp.Dependencies) $(Tmp.ObjPath)/.dir
$(Summary) " ASSEMBLE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$<"
- $(Verb) $(Tmp.CC) $(Tmp.ArchFlag) $(Tmp.CFLAGS) -c -o $$@ $$<
+ $(Verb) $(Tmp.CC) $(Tmp.CFLAGS) -c -o $$@ $$<
$(Tmp.ObjPath)/%.o: $(Tmp.SrcPath)/%.S $(Tmp.Dependencies) $(Tmp.ObjPath)/.dir
$(Summary) " ASSEMBLE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$<"
- $(Verb) $(Tmp.CC) $(Tmp.ArchFlag) $(Tmp.CFLAGS) -c -o $$@ $$<
+ $(Verb) $(Tmp.CC) $(Tmp.CFLAGS) -c -o $$@ $$<
$(Tmp.ObjPath)/%.o: $(Tmp.SrcPath)/%.c $(Tmp.Dependencies) $(Tmp.ObjPath)/.dir
$(Summary) " COMPILE: $(Tmp.Name)/$(Tmp.Config)/$(Tmp.Arch): $$<"
- $(Verb) $(Tmp.CC) $(Tmp.ArchFlag) $(Tmp.CFLAGS) -c -o $$@ $$<
+ $(Verb) $(Tmp.CC) $(Tmp.CFLAGS) -c -o $$@ $$<
.PRECIOUS: $(Tmp.ObjPath)/.dir
endef
diff --git a/compiler-rt/lib/assembly.h b/compiler-rt/lib/assembly.h
index e6b8410..c2d5a34 100644
--- a/compiler-rt/lib/assembly.h
+++ b/compiler-rt/lib/assembly.h
@@ -30,9 +30,16 @@
#define SYMBOL_NAME(name) name
#endif
+#ifdef VISIBILITY_HIDDEN
+#define DEFINE_COMPILERRT_FUNCTION(name) \
+ .globl SYMBOL_NAME(name) SEPARATOR \
+ .private_extern SYMBOL_NAME(name) SEPARATOR \
+ SYMBOL_NAME(name):
+#else
#define DEFINE_COMPILERRT_FUNCTION(name) \
.globl SYMBOL_NAME(name) SEPARATOR \
SYMBOL_NAME(name):
+#endif
#define DEFINE_COMPILERRT_PRIVATE_FUNCTION(name) \
.globl SYMBOL_NAME(name) SEPARATOR \
diff --git a/compiler-rt/make/lib_info.mk b/compiler-rt/make/lib_info.mk
index 91ee23b..a54152a 100644
--- a/compiler-rt/make/lib_info.mk
+++ b/compiler-rt/make/lib_info.mk
@@ -46,4 +46,5 @@
# The names of all the available options.
AvailableOptions := AR ARFLAGS \
CC CFLAGS FUNCTIONS OPTIMIZED \
- RANLIB RANLIBFLAGS
+ RANLIB RANLIBFLAGS \
+ VISIBILITY_HIDDEN
diff --git a/compiler-rt/make/options.mk b/compiler-rt/make/options.mk
index 392bbdd..f6a331b 100644
--- a/compiler-rt/make/options.mk
+++ b/compiler-rt/make/options.mk
@@ -15,6 +15,14 @@
# Whether optimized function implementations should be used.
OPTIMIZED := 1
+# Whether function definitions should use hidden visibility. This adds the
+# -fvisibility=hidden compiler option and uses .private_extern annotations in
+# assembly files.
+#
+# FIXME: Make this more portable. When that is done, it should probably be the
+# default.
+VISIBILITY_HIDDEN := 0
+
# Miscellaneous tools.
AR := ar
diff --git a/compiler-rt/make/platform/darwin_bni.mk b/compiler-rt/make/platform/darwin_bni.mk
index 952b104..e713d24 100644
--- a/compiler-rt/make/platform/darwin_bni.mk
+++ b/compiler-rt/make/platform/darwin_bni.mk
@@ -50,3 +50,4 @@
subdf3vfp subsf3vfp truncdfsf2vfp unorddf2vfp unordsf2vfp \
modsi3 umodsi3 udivsi3 divsi3 switch save_restore_d8_d15
+VISIBILITY_HIDDEN := 0
diff --git a/compiler-rt/make/platform/darwin_fat.mk b/compiler-rt/make/platform/darwin_fat.mk
index cea2a51..3659e04 100644
--- a/compiler-rt/make/platform/darwin_fat.mk
+++ b/compiler-rt/make/platform/darwin_fat.mk
@@ -51,3 +51,5 @@
FUNCTIONS.armv7 := $(CommonFunctions) $(ArchFunctions.armv7)
OPTIMIZED.Debug := 0
+
+VISIBILITY_HIDDEN := 1
diff --git a/compiler-rt/make/platform/multi_arch.mk b/compiler-rt/make/platform/multi_arch.mk
index c85f3d9..eebc7b2 100644
--- a/compiler-rt/make/platform/multi_arch.mk
+++ b/compiler-rt/make/platform/multi_arch.mk
@@ -13,4 +13,4 @@
CFLAGS.m64 := $(CFLAGS) -m64 -O3
FUNCTIONS := moddi3 floatundixf udivdi3
-FUNCTIONS.m64 := $(FUNCTIONS) lshrdi3
\ No newline at end of file
+FUNCTIONS.m64 := $(FUNCTIONS) lshrdi3