Skip to content

Commit 1b16a39

Browse files
authored
Fix some issues with llvm source build (#57792)
- The build fails if any runtime is enabled as `LLVM_ENABLE_RUNTIMES` will start with `;` which it seems to interpret as a runtime whose name is the empty string. - When llvm links against libLLVM, this fails as some of the compilers on CI set a sysroot causing zlib to not be found, see llvm/llvm-project#131119. - Also, fix freebsd build by compiling statically linked code with `-fPIC`.
1 parent edf7657 commit 1b16a39

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

deps/llvm.mk

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ ifeq ($(BUILD_LLD), 1)
6060
LLVM_ENABLE_PROJECTS := $(LLVM_ENABLE_PROJECTS);lld
6161
endif
6262

63+
# Remove ; if it's the first character
64+
ifneq ($(LLVM_ENABLE_RUNTIMES),)
65+
LLVM_ENABLE_RUNTIMES := $(patsubst ;%,%,$(LLVM_ENABLE_RUNTIMES))
66+
endif
6367

6468
LLVM_LIB_FILE := libLLVMCodeGen.a
6569

@@ -70,7 +74,7 @@ LLVM_EXPERIMENTAL_TARGETS :=
7074
LLVM_CFLAGS :=
7175
LLVM_CXXFLAGS :=
7276
LLVM_CPPFLAGS :=
73-
LLVM_LDFLAGS :=
77+
LLVM_LDFLAGS := "-L$(build_shlibdir)" # hacky way to force zlib to be found when linking against libLLVM and sysroot is set
7478
LLVM_CMAKE :=
7579

7680
LLVM_CMAKE += -DLLVM_ENABLE_PROJECTS="$(LLVM_ENABLE_PROJECTS)"
@@ -183,6 +187,11 @@ endif
183187

184188
ifeq ($(fPIC),)
185189
LLVM_CMAKE += -DLLVM_ENABLE_PIC=OFF
190+
else
191+
ifeq ($(OS),FreeBSD)
192+
# On FreeBSD, we must force even statically-linked code to have -fPIC
193+
LLVM_CMAKE += -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
194+
endif
186195
endif
187196

188197
LLVM_CMAKE += -DCMAKE_C_FLAGS="$(LLVM_CPPFLAGS) $(LLVM_CFLAGS)" \

0 commit comments

Comments
 (0)