backend/build: improve LLVM link options
Update options according to llvm-config: * delete "--stdlib=libc++" (it seems to provoke runtime link errors on Linux) * remove "-lffi" (it doesn't seem to be required) * remove "-lc++" on macOS Also move Linux system libs options to llvm.def (as for macOS)
This commit is contained in:
committed by
SvyatoslavScherbina
parent
d1a303bb25
commit
3d36973022
+46
-44
@@ -62,57 +62,59 @@ compileCompilerKotlin {
|
|||||||
dependsOn('generateCompilerProto')
|
dependsOn('generateCompilerProto')
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] linkerOpts1() {
|
List<String> llvmLinkerOpts() {
|
||||||
def libs = ['-lLLVMX86Disassembler',
|
// TODO: cannot use llvm-config because it can be inaccessible during project configuration
|
||||||
'-lLLVMX86AsmParser',
|
final List<String> libs = [
|
||||||
'-lLLVMX86CodeGen',
|
'-lLLVMX86Disassembler',
|
||||||
'-lLLVMSelectionDAG',
|
'-lLLVMX86AsmParser',
|
||||||
'-lLLVMAsmPrinter',
|
'-lLLVMX86CodeGen',
|
||||||
'-lLLVMX86Desc',
|
'-lLLVMSelectionDAG',
|
||||||
'-lLLVMMCDisassembler',
|
'-lLLVMAsmPrinter',
|
||||||
'-lLLVMX86Info',
|
'-lLLVMX86Desc',
|
||||||
'-lLLVMX86AsmPrinter',
|
'-lLLVMMCDisassembler',
|
||||||
'-lLLVMX86Utils',
|
'-lLLVMX86Info',
|
||||||
'-lLLVMInterpreter',
|
'-lLLVMX86AsmPrinter',
|
||||||
'-lLLVMCodeGen',
|
'-lLLVMX86Utils',
|
||||||
'-lLLVMScalarOpts',
|
'-lLLVMInterpreter',
|
||||||
'-lLLVMInstCombine',
|
'-lLLVMCodeGen',
|
||||||
'-lLLVMInstrumentation',
|
'-lLLVMScalarOpts',
|
||||||
'-lLLVMProfileData',
|
'-lLLVMInstCombine',
|
||||||
'-lLLVMTransformUtils',
|
'-lLLVMInstrumentation',
|
||||||
'-lLLVMBitWriter',
|
'-lLLVMProfileData',
|
||||||
'-lLLVMExecutionEngine',
|
'-lLLVMTransformUtils',
|
||||||
'-lLLVMTarget',
|
'-lLLVMBitWriter',
|
||||||
'-lLLVMAnalysis',
|
'-lLLVMExecutionEngine',
|
||||||
'-lLLVMRuntimeDyld',
|
'-lLLVMTarget',
|
||||||
'-lLLVMObject',
|
'-lLLVMAnalysis',
|
||||||
'-lLLVMMCParser',
|
'-lLLVMRuntimeDyld',
|
||||||
'-lLLVMBitReader',
|
'-lLLVMObject',
|
||||||
'-lLLVMMC',
|
'-lLLVMMCParser',
|
||||||
'-lLLVMCore',
|
'-lLLVMBitReader',
|
||||||
'-lLLVMSupport']
|
'-lLLVMMC',
|
||||||
List<String> ldflags = new ArrayList<>()
|
'-lLLVMCore',
|
||||||
if (isLinux())
|
'-lLLVMSupport'
|
||||||
ldflags.addAll(["-L$llvmDir/lib",
|
]
|
||||||
"-Wl,-Bstatic", "-Wl,--whole-archive"]
|
|
||||||
|
final List<String> res = new ArrayList<>()
|
||||||
|
|
||||||
|
res << "-L$llvmDir/lib"
|
||||||
|
|
||||||
|
if (isLinux()) {
|
||||||
|
res.addAll(["-Wl,-Bstatic", "-Wl,--whole-archive"]
|
||||||
+ libs
|
+ libs
|
||||||
+ ["-Wl,--no-whole-archive", "-Wl,-Bdynamic",
|
+ ["-Wl,--no-whole-archive", "-Wl,-Bdynamic"])
|
||||||
"-L$libffiDir/lib -lffi",
|
} else {
|
||||||
"-lrt", "-ldl","-lpthread", "-lz", "-lm"])
|
res.addAll(libs)
|
||||||
else
|
}
|
||||||
ldflags.addAll(["-L$llvmDir/lib", "-lc++"]
|
|
||||||
+ libs
|
return res
|
||||||
+ ["-L$libffiDir/lib", "-lffi"])
|
|
||||||
ArrayList<String> strldflags = new ArrayList<>()
|
|
||||||
ldflags.forEach{strldflags.add(it.toString())}
|
|
||||||
return strldflags.toArray(new String[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinNativeInterop {
|
kotlinNativeInterop {
|
||||||
llvm {
|
llvm {
|
||||||
defFile 'llvm.def'
|
defFile 'llvm.def'
|
||||||
compilerOpts "-fPIC", "-I$llvmDir/include"
|
compilerOpts "-fPIC", "-I$llvmDir/include"
|
||||||
linkerOpts linkerOpts1()
|
linkerOpts llvmLinkerOpts()
|
||||||
}
|
}
|
||||||
|
|
||||||
hash { // TODO: copy-pasted from ':common:compileHash'
|
hash { // TODO: copy-pasted from ':common:compileHash'
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ compilerOpts = -std=c99 -fPIC \
|
|||||||
|
|
||||||
linker = clang++
|
linker = clang++
|
||||||
|
|
||||||
linkerOpts = -stdlib=libc++ -fPIC -fvisibility-inlines-hidden \
|
linkerOpts = -fPIC -fvisibility-inlines-hidden \
|
||||||
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \
|
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \
|
||||||
-pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \
|
-pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \
|
||||||
-std=c++11 \
|
-std=c++11 \
|
||||||
@@ -19,4 +19,5 @@ linkerOpts.osx = \
|
|||||||
-lpthread -lz -lm -lcurses
|
-lpthread -lz -lm -lcurses
|
||||||
|
|
||||||
linkerOpts.linux=\
|
linkerOpts.linux=\
|
||||||
-Wl,-z,noexecstack
|
-Wl,-z,noexecstack \
|
||||||
|
-lrt -ldl -lpthread -lz -lm
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ class NamedNativeInteropConfig implements Named {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void linkerOpts(String... values) {
|
void linkerOpts(String... values) {
|
||||||
|
this.linkerOpts(values.toList())
|
||||||
|
}
|
||||||
|
|
||||||
|
void linkerOpts(List<String> values) {
|
||||||
linkerOpts.addAll(values)
|
linkerOpts.addAll(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user