Skip to content

Commit 0b4602b

Browse files
committed
add SYMBOLPREFIX and SYMBOLSUFFIX makefile options
for adding a prefix or suffix to all exported symbol names in the shared library Useful to avoid conflicts with other BLAS libraries, especially when using 64 bit integer interfaces in OpenBLAS Note that since OSX does not have the objcopy utility, setting these options to non-empty values on Mac requires the objconv tool, available (GPL license) from http://www.agner.org/optimize/#objconv
1 parent ac5a7e1 commit 0b4602b

3 files changed

Lines changed: 116 additions & 36 deletions

File tree

Makefile.system

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ LD = $(CROSS_SUFFIX)ld
186186
RANLIB = $(CROSS_SUFFIX)ranlib
187187
NM = $(CROSS_SUFFIX)nm
188188
DLLWRAP = $(CROSS_SUFFIX)dllwrap
189+
OBJCOPY = $(CROSS_SUFFIX)objcopy
190+
OBJCONV = $(CROSS_SUFFIX)objconv
189191

190192
#
191193
# OS dependent settings
@@ -845,6 +847,14 @@ else
845847
LIBPREFIX = libopenblas_$(LIBNAMESUFFIX)
846848
endif
847849

850+
ifndef SYMBOLPREFIX
851+
SYMBOLPREFIX =
852+
endif
853+
854+
ifndef SYMBOLSUFFIX
855+
SYMBOLSUFFIX =
856+
endif
857+
848858
KERNELDIR = $(TOPDIR)/kernel/$(ARCH)
849859

850860
include $(TOPDIR)/Makefile.$(ARCH)

exports/Makefile

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,18 @@ dll : ../$(LIBDLLNAME)
8888
-Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive $(FEXTRALIB) $(EXTRALIB)
8989

9090
libopenblas.def : gensymbol
91-
perl ./gensymbol win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) > $(@F)
91+
perl ./gensymbol win2k $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" > $(@F)
9292

9393
libgoto_hpl.def : gensymbol
94-
perl ./gensymbol win2khpl $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) > $(@F)
94+
perl ./gensymbol win2khpl $(ARCH) dummy $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" > $(@F)
9595

96+
ifeq (, $(SYMBOLPREFIX)$(SYMBOLSUFFIX))
9697
$(LIBDYNNAME) : ../$(LIBNAME) osx.def
98+
else
99+
../$(LIBNAME).renamed : ../$(LIBNAME) objconv.def
100+
$(OBJCONV) @objconv.def ../$(LIBNAME) ../$(LIBNAME).renamed
101+
$(LIBDYNNAME) : ../$(LIBNAME).renamed osx.def
102+
endif
97103
$(FC) $(FFLAGS) -all_load -headerpad_max_install_names -install_name $(CURDIR)/../$(LIBDYNNAME) -dynamiclib -o ../$(LIBDYNNAME) $< -Wl,-exported_symbols_list,osx.def $(FEXTRALIB)
98104

99105
dllinit.$(SUFFIX) : dllinit.c
@@ -103,16 +109,22 @@ ifeq ($(OSNAME), Linux)
103109

104110
so : ../$(LIBSONAME)
105111

112+
ifeq (, $(SYMBOLPREFIX)$(SYMBOLSUFFIX))
106113
../$(LIBSONAME) : ../$(LIBNAME) linktest.c
114+
else
115+
../$(LIBNAME).renamed : ../$(LIBNAME) objcopy.def
116+
$(OBJCOPY) --redefine-syms objcopy.def ../$(LIBNAME) ../$(LIBNAME).renamed
117+
../$(LIBSONAME) : ../$(LIBNAME).renamed linktest.c
118+
endif
107119
ifneq ($(C_COMPILER), LSB)
108120
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o ../$(LIBSONAME) \
109-
-Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive \
121+
-Wl,--whole-archive $< -Wl,--no-whole-archive \
110122
-Wl,-soname,$(LIBPREFIX).so.$(MAJOR_VERSION) $(EXTRALIB)
111123
$(CC) $(CFLAGS) $(LDFLAGS) -w -o linktest linktest.c ../$(LIBSONAME) $(FEXTRALIB) && echo OK.
112124
else
113125
#for LSB
114126
env LSBCC_SHAREDLIBS=gfortran $(CC) $(CFLAGS) $(LDFLAGS) -shared -o ../$(LIBSONAME) \
115-
-Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive \
127+
-Wl,--whole-archive $< -Wl,--no-whole-archive \
116128
-Wl,-soname,$(LIBPREFIX).so.$(MAJOR_VERSION) $(EXTRALIB)
117129
$(FC) $(CFLAGS) $(LDFLAGS) -w -o linktest linktest.c ../$(LIBSONAME) $(FEXTRALIB) && echo OK.
118130
endif
@@ -125,9 +137,15 @@ ifeq ($(OSNAME), $(filter $(OSNAME),FreeBSD NetBSD))
125137

126138
so : ../$(LIBSONAME)
127139

140+
ifeq (, $(SYMBOLPREFIX)$(SYMBOLSUFFIX))
128141
../$(LIBSONAME) : ../$(LIBNAME) linktest.c
142+
else
143+
../$(LIBNAME).renamed : ../$(LIBNAME) objcopy.def
144+
$(OBJCOPY) --redefine-syms objcopy.def ../$(LIBNAME) ../$(LIBNAME).renamed
145+
../$(LIBSONAME) : ../$(LIBNAME).renamed linktest.c
146+
endif
129147
$(CC) $(CFLAGS) $(LDFLAGS) -shared -o ../$(LIBSONAME) \
130-
-Wl,--whole-archive ../$(LIBNAME) -Wl,--no-whole-archive \
148+
-Wl,--whole-archive $< -Wl,--no-whole-archive \
131149
$(FEXTRALIB) $(EXTRALIB)
132150
$(CC) $(CFLAGS) $(LDFLAGS) -w -o linktest linktest.c ../$(LIBSONAME) $(FEXTRALIB) && echo OK.
133151
rm -f linktest
@@ -178,17 +196,23 @@ static : ../$(LIBNAME)
178196
rm -f goto.$(SUFFIX)
179197

180198
osx.def : gensymbol ../Makefile.system ../getarch.c
181-
perl ./gensymbol osx $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) > $(@F)
199+
perl ./gensymbol osx $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" > $(@F)
182200

183201
aix.def : gensymbol ../Makefile.system ../getarch.c
184-
perl ./gensymbol aix $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) > $(@F)
202+
perl ./gensymbol aix $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" > $(@F)
203+
204+
objcopy.def : gensymbol ../Makefile.system ../getarch.c
205+
perl ./gensymbol objcopy $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" > $(@F)
206+
207+
objconv.def : gensymbol ../Makefile.system ../getarch.c
208+
perl ./gensymbol objconv $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" > $(@F)
185209

186210
test : linktest.c
187211
$(CC) $(CFLAGS) $(LDFLAGS) -w -o linktest linktest.c ../$(LIBSONAME) -lm && echo OK.
188212
rm -f linktest
189213

190214
linktest.c : gensymbol ../Makefile.system ../getarch.c
191-
perl ./gensymbol linktest $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) > linktest.c
215+
perl ./gensymbol linktest $(ARCH) $(BU) $(EXPRECISION) $(NO_CBLAS) $(NO_LAPACK) $(NO_LAPACKE) $(NEED2UNDERSCORES) $(ONLY_CBLAS) "$(SYMBOLPREFIX)" "$(SYMBOLSUFFIX)" > linktest.c
192216

193217
clean ::
194218
@rm -f *.def *.dylib __.SYMDEF*

exports/gensymbol

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,22 +2784,26 @@ $bu = $ARGV[2];
27842784

27852785
$bu = "" if (($bu eq "0") || ($bu eq "1"));
27862786

2787+
$symbolprefix = $ARGV[9];
2788+
2789+
$symbolsuffix = $ARGV[10];
2790+
27872791
if ($ARGV[0] eq "osx"){
27882792

27892793
@underscore_objs = (@underscore_objs, @misc_common_objs);
27902794
@no_underscore_objs = (@no_underscore_objs, @misc_common_objs);
27912795

27922796
foreach $objs (@underscore_objs) {
2793-
print "_", $objs, $bu, "\n";
2797+
print "_", $symbolprefix, $objs, $bu, $symbolsuffix, "\n";
27942798
}
27952799

27962800
foreach $objs (@need_2underscore_objs) {
2797-
print "_", $objs, $bu, $bu, "\n";
2801+
print "_", $symbolprefix, $objs, $bu, $bu, $symbolsuffix, "\n";
27982802
}
27992803

28002804
# if ($ARGV[4] == 0) {
28012805
foreach $objs (@no_underscore_objs) {
2802-
print "_", $objs, "\n";
2806+
print "_", $symbolprefix, $objs, $symbolsuffix, "\n";
28032807
}
28042808
# }
28052809
exit(0);
@@ -2811,16 +2815,58 @@ if ($ARGV[0] eq "aix"){
28112815
@no_underscore_objs = (@no_underscore_objs, @misc_common_objs);
28122816

28132817
foreach $objs (@underscore_objs) {
2814-
print $objs, $bu, "\n";
2818+
print $symbolprefix, $objs, $bu, $symbolsuffix, "\n";
2819+
}
2820+
2821+
foreach $objs (@need_2underscore_objs) {
2822+
print $symbolprefix, $objs, $bu, $bu, $symbolsuffix, "\n";
2823+
}
2824+
2825+
# if ($ARGV[4] == 0) {
2826+
foreach $objs (@no_underscore_objs) {
2827+
print $symbolprefix, $objs, $symbolsuffix, "\n";
2828+
}
2829+
# }
2830+
exit(0);
2831+
}
2832+
2833+
if ($ARGV[0] eq "objcopy"){
2834+
2835+
@underscore_objs = (@underscore_objs, @misc_common_objs);
2836+
@no_underscore_objs = (@no_underscore_objs, @misc_common_objs);
2837+
2838+
foreach $objs (@underscore_objs) {
2839+
print $objs, $bu, " ", $symbolprefix, $objs, $bu, $symbolsuffix, "\n";
2840+
}
2841+
2842+
foreach $objs (@need_2underscore_objs) {
2843+
print $objs, $bu, $bu, " ", $symbolprefix, $objs, $bu, $bu, $symbolsuffix, "\n";
2844+
}
2845+
2846+
# if ($ARGV[4] == 0) {
2847+
foreach $objs (@no_underscore_objs) {
2848+
print $objs, " ", $symbolprefix, $objs, $symbolsuffix, "\n";
2849+
}
2850+
# }
2851+
exit(0);
2852+
}
2853+
2854+
if ($ARGV[0] eq "objconv"){
2855+
2856+
@underscore_objs = (@underscore_objs, @misc_common_objs);
2857+
@no_underscore_objs = (@no_underscore_objs, @misc_common_objs);
2858+
2859+
foreach $objs (@underscore_objs) {
2860+
print "-nr:_", $objs, $bu, ":_", $symbolprefix, $objs, $bu, $symbolsuffix, "\n";
28152861
}
28162862

28172863
foreach $objs (@need_2underscore_objs) {
2818-
print $objs, $bu, $bu, "\n";
2864+
print "-nr:_", $objs, $bu, $bu, ":_", $symbolprefix, $objs, $bu, $bu, $symbolsuffix, "\n";
28192865
}
28202866

28212867
# if ($ARGV[4] == 0) {
28222868
foreach $objs (@no_underscore_objs) {
2823-
print $objs, "\n";
2869+
print "-nr:_", $objs, ":_", $symbolprefix, $objs, $symbolsuffix, "\n";
28242870
}
28252871
# }
28262872
exit(0);
@@ -2835,22 +2881,22 @@ if ($ARGV[0] eq "win2k"){
28352881
foreach $objs (@underscore_objs) {
28362882
$uppercase = $objs;
28372883
$uppercase =~ tr/[a-z]/[A-Z]/;
2838-
print "\t$objs=$objs","_ \@", $count, "\n";
2884+
print "\t",$symbolprefix, $objs, $symbolsuffix, "=$objs","_ \@", $count, "\n";
28392885
$count ++;
2840-
print "\t",$objs, "_=$objs","_ \@", $count, "\n";
2886+
print "\t",$symbolprefix, $objs, "_", $symbolsuffix, "=$objs","_ \@", $count, "\n";
28412887
$count ++;
2842-
print "\t$uppercase=$objs", "_ \@", $count, "\n";
2888+
print "\t",$symbolprefix, $uppercase, $symbolsuffix, "=$objs", "_ \@", $count, "\n";
28432889
$count ++;
28442890
}
28452891

28462892
foreach $objs (@need_2underscore_objs) {
28472893
$uppercase = $objs;
28482894
$uppercase =~ tr/[a-z]/[A-Z]/;
2849-
print "\t$objs=$objs","__ \@", $count, "\n";
2895+
print "\t",$symbolprefix, $objs, $symbolsuffix, "=$objs","__ \@", $count, "\n";
28502896
$count ++;
2851-
print "\t",$objs, "__=$objs","__ \@", $count, "\n";
2897+
print "\t",$symbolprefix, $objs, "__", $symbolsuffix, "=$objs","__ \@", $count, "\n";
28522898
$count ++;
2853-
print "\t$uppercase=$objs", "__ \@", $count, "\n";
2899+
print "\t",$symbolprefix, $uppercase, $symbolsuffix, "=$objs", "__ \@", $count, "\n";
28542900
$count ++;
28552901
}
28562902

@@ -2859,15 +2905,15 @@ if ($ARGV[0] eq "win2k"){
28592905

28602906
$uppercase = $objs;
28612907
$uppercase =~ tr/[a-z]/[A-Z]/;
2862-
print "\t",$objs, "_=$objs","_ \@", $count, "\n";
2908+
print "\t",$symbolprefix, $objs, "_", $symbolsuffix, "=$objs","_ \@", $count, "\n";
28632909
$count ++;
2864-
print "\t$uppercase=$objs", "_ \@", $count, "\n";
2910+
print "\t",$symbolprefix, $uppercase, $symbolsuffix, "=$objs", "_ \@", $count, "\n";
28652911
$count ++;
28662912
}
28672913

28682914

28692915
foreach $objs (@no_underscore_objs) {
2870-
print "\t",$objs,"=$objs"," \@", $count, "\n";
2916+
print "\t",$symbolprefix,$objs,$symbolsuffix,"=$objs"," \@", $count, "\n";
28712917
$count ++;
28722918
}
28732919

@@ -2880,11 +2926,11 @@ if ($ARGV[0] eq "win2khpl"){
28802926
foreach $objs (@hplobjs) {
28812927
$uppercase = $objs;
28822928
$uppercase =~ tr/[a-z]/[A-Z]/;
2883-
print "\t$objs=$objs","_ \@", $count, "\n";
2929+
print "\t",$symbolprefix, $objs, $symbolsuffix, "=$objs","_ \@", $count, "\n";
28842930
$count ++;
2885-
print "\t",$objs, "_=$objs","_ \@", $count, "\n";
2931+
print "\t",$symbolprefix, $objs, "_", $symbolsuffix, "=$objs","_ \@", $count, "\n";
28862932
$count ++;
2887-
print "\t$uppercase=$objs", "_ \@", $count, "\n";
2933+
print "\t",$symbolprefix, $uppercase, $symbolsuffix, "=$objs", "_ \@", $count, "\n";
28882934
$count ++;
28892935
}
28902936

@@ -2905,24 +2951,24 @@ if ($ARGV[0] eq "microsoft"){
29052951
foreach $objs (@underscore_objs) {
29062952
$uppercase = $objs;
29072953
$uppercase =~ tr/[a-z]/[A-Z]/;
2908-
print "\t$objs = $objs","_\n";
2954+
print "\t",$symbolprefix, $objs, $symbolsuffix, " = $objs","_\n";
29092955
$count ++;
2910-
print "\t$objs\_ = $objs","_\n";
2956+
print "\t",$symbolprefix, $objs, "\_", $symbolsuffix, " = $objs","_\n";
29112957
$count ++;
2912-
print "\t$uppercase = $objs","_\n";
2958+
print "\t",$symbolprefix, $uppercase, $symbolsuffix, " = $objs","_\n";
29132959
$count ++;
2914-
print "\t$uppercase\_ = $objs","_\n";
2960+
print "\t",$symbolprefix, $uppercase, "\_", $symbolsuffix, " = $objs","_\n";
29152961
$count ++;
29162962
}
29172963

29182964
foreach $objs (@need_2underscore_objs) {
29192965
$uppercase = $objs;
29202966
$uppercase =~ tr/[a-z]/[A-Z]/;
2921-
print "\t$objs=$objs","__ \@", $count, "\n";
2967+
print "\t",$symbolprefix, $objs, $symbolsuffix, "=$objs","__ \@", $count, "\n";
29222968
$count ++;
2923-
print "\t",$objs, "__=$objs","__ \@", $count, "\n";
2969+
print "\t",$symbolprefix, $objs, "__", $symbolsuffix, "=$objs","__ \@", $count, "\n";
29242970
$count ++;
2925-
print "\t$uppercase=$objs", "__ \@", $count, "\n";
2971+
print "\t",$symbolprefix, $uppercase, $symbolsuffix, "=$objs", "__ \@", $count, "\n";
29262972
$count ++;
29272973
}
29282974

@@ -2936,16 +2982,16 @@ if ($ARGV[0] eq "linktest"){
29362982

29372983
print "int main(void){\n";
29382984
foreach $objs (@underscore_objs) {
2939-
print $objs, $bu, "();\n" if $objs ne "xerbla";
2985+
print $symbolprefix, $objs, $bu, $symbolsuffix, "();\n" if $objs ne "xerbla";
29402986
}
29412987

29422988
foreach $objs (@need_2underscore_objs) {
2943-
print $objs, $bu, $bu, "();\n";
2989+
print $symbolprefix, $objs, $bu, $bu, $symbolsuffix, "();\n";
29442990
}
29452991

29462992
# if ($ARGV[4] == 0) {
29472993
foreach $objs (@no_underscore_objs) {
2948-
print $objs, "();\n";
2994+
print $symbolprefix, $objs, $symbolsuffix, "();\n";
29492995
}
29502996
# }
29512997

0 commit comments

Comments
 (0)