Skip to content

Commit 6341e3e

Browse files
authored
Carry LLVM patch that limits llvm-config flags (#32400)
This is an LLVM 6.0/7.0 backport of a patch that changes which flags llvm-config passes. This shouldn't matter much for most uses cases, but it's useful for two reasons: 1) It makes the behavior of llvm-config consistent between all the LLVM versions we support, making it easier for find any problems with our Makefile. 2) It prevents any flags meant for LLVM only from creeping into the build of our .cpp files (there isn't usually a need for this, but I needed to be able to do this when trying to target wasm)
1 parent 98168bc commit 6341e3e

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

deps/llvm.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ endif
435435
$(eval $(call LLVM_PATCH,llvm-D51842-win64-byval-cc))
436436
$(eval $(call LLVM_PATCH,llvm-D57118-powerpc))
437437
$(eval $(call LLVM_PATCH,llvm-r355582-avxminmax)) # remove for 8.0
438+
$(eval $(call LLVM_PATCH,llvm-rL349068-llvm-config)) # remove for 8.0
438439
endif # LLVM_VER 6.0
439440

440441
ifeq ($(LLVM_VER_SHORT),7.0)
@@ -449,6 +450,7 @@ $(eval $(call LLVM_PATCH,llvm-7.0-D50167-scev-umin))
449450
$(eval $(call LLVM_PATCH,llvm7-windows-race))
450451
$(eval $(call LLVM_PATCH,llvm7-D51842-win64-byval-cc)) # remove for 8.0
451452
$(eval $(call LLVM_PATCH,llvm-D57118-powerpc))
453+
$(eval $(call LLVM_PATCH,llvm-rL349068-llvm-config)) # remove for 8.0
452454
endif # LLVM_VER 7.0
453455

454456
ifeq ($(LLVM_VER_SHORT),8.0)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
commit befe7b1ade08aad7a048ac5ed2d03b92605977a7
2+
Author: Tom Stellard <[email protected]>
3+
Date: Thu Dec 13 18:21:23 2018 +0000
4+
5+
Don't add unnecessary compiler flags to llvm-config output
6+
7+
Summary:
8+
llvm-config --cxxflags --cflags, should only output the minimal flags
9+
required to link against the llvm libraries. They currently contain
10+
all flags used to compile llvm including flags like -g, -pedantic,
11+
-Wall, etc, which users may not always want.
12+
13+
This changes the llvm-config output to only include flags that have been
14+
explictly added to the COMPILE_FLAGS property of the llvm-config target
15+
by the llvm build system.
16+
17+
llvm.org/PR8220
18+
19+
Output from llvm-config when running cmake with:
20+
cmake -G Ninja .. -DCMAKE_CXX_FLAGS=-funroll-loops
21+
22+
Before:
23+
24+
--cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include
25+
-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
26+
--cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include
27+
-fPIC -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings \
28+
-Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough \
29+
-Wno-comment -fdiagnostics-color -g -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS \
30+
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
31+
--cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include\
32+
-funroll-loops -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall \
33+
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers \
34+
-pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized \
35+
-Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment \
36+
-fdiagnostics-color -g -fno-exceptions -fno-rtti -D_GNU_SOURCE -D_DEBUG \
37+
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
38+
39+
After:
40+
41+
--cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \
42+
-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
43+
--cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \
44+
-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
45+
--cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \
46+
-std=c++11 -fno-exceptions -fno-rtti \
47+
-D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
48+
49+
Reviewers: sylvestre.ledru, infinity0, mgorny
50+
51+
Reviewed By: sylvestre.ledru, mgorny
52+
53+
Subscribers: mgorny, dmgreen, llvm-commits
54+
55+
Differential Revision: https://reviews.llvm.org/D55391
56+
57+
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349068 91177308-0d34-0410-b5e6-96231b3b80d8
58+
59+
diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
60+
index a0bd36c3731..a7db17386fb 100644
61+
--- a/tools/llvm-config/CMakeLists.txt
62+
+++ b/tools/llvm-config/CMakeLists.txt
63+
@@ -29,12 +29,20 @@ string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
64+
# Fetch target specific compile options, e.g. RTTI option
65+
get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
66+
67+
+# The language standard potentially affects the ABI/API of LLVM, so we want
68+
+# to make sure it is reported by llvm-config.
69+
+# NOTE: We don't want to start extracting any random C/CXX flags that the
70+
+# user may add that could affect the ABI. We only want to extract flags
71+
+# that have been added by the LLVM build system.
72+
+string(REGEX MATCH "-std=[^ ]\+" LLVM_CXX_STD_FLAG ${CMAKE_CXX_FLAGS})
73+
+string(REGEX MATCH "-std=[^ ]\+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS})
74+
+
75+
# Use configure_file to create BuildVariables.inc.
76+
set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
77+
set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
78+
-set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
79+
-set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
80+
-set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
81+
+set(LLVM_CPPFLAGS "${LLVM_DEFINITIONS}")
82+
+set(LLVM_CFLAGS "${LLVM_C_STD_FLAG} ${LLVM_DEFINITIONS}")
83+
+set(LLVM_CXXFLAGS "${LLVM_CXX_STD_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
84+
set(LLVM_BUILD_SYSTEM cmake)
85+
set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
86+
set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")

0 commit comments

Comments
 (0)