Bug 1403346 - Implement cflags filtering for elfhack in mozbuild COMPILE_FLAGS
MozReview-Commit-ID: GO2mqMjHuHd
--- a/build/unix/elfhack/Makefile.in
+++ b/build/unix/elfhack/Makefile.in
@@ -1,15 +1,13 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-OS_CXXFLAGS := $(filter-out -fno-exceptions,$(OS_CXXFLAGS)) -fexceptions
-
include $(topsrcdir)/config/rules.mk
test-array$(DLL_SUFFIX) test-ctors$(DLL_SUFFIX): %$(DLL_SUFFIX): %.$(OBJ_SUFFIX) elfhack
$(MKSHLIB) $(LDFLAGS) $< -nostartfiles
@echo ===
@echo === If you get failures below, please file a bug describing the error
@echo === and your environment \(compiler and linker versions\), and
@echo === provide the pre-elfhacked library as an attachment.
--- a/build/unix/elfhack/inject/Makefile.in
+++ b/build/unix/elfhack/inject/Makefile.in
@@ -4,10 +4,8 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
include $(topsrcdir)/config/rules.mk
$(CSRCS): %.c: ../inject.c
cp $< $@
GARBAGE += $(CSRCS)
-
-CFLAGS := -O2 -fno-stack-protector $(filter -m% -I% -idirafter%,$(subst -idirafter ,-idirafter,$(CFLAGS)))
--- a/build/unix/elfhack/inject/moz.build
+++ b/build/unix/elfhack/inject/moz.build
@@ -18,9 +18,24 @@ else:
cpu = CONFIG['TARGET_CPU']
SOURCES += [
"!%s.c" % cpu,
]
NO_PGO = True
+for v in ('OS_CPPFLAGS', 'OS_CFLAGS', 'DEBUG', 'CLANG_PLUGIN', 'OPTIMIZE',
+ 'FRAMEPTR'):
+ flags = []
+ idx = 0
+ for flag in COMPILE_FLAGS[v]:
+ if flag == '-idirafter':
+ flags.append(''.join(COMPILE_FLAGS[v][idx:idx + 2]))
+ elif flag.startswith(('-m', '-I', '-idirafter')):
+ flags.append(flag)
+ idx += 1
+ COMPILE_FLAGS[v] = flags
+
+COMPILE_FLAGS['OS_CFLAGS'] += ['-O2', '-fno-stack-protector']
+
+AllowCompilerWarnings()
NoVisibilityFlags()
--- a/build/unix/elfhack/moz.build
+++ b/build/unix/elfhack/moz.build
@@ -21,8 +21,13 @@ if not CONFIG['CROSS_COMPILE']:
HOST_SOURCES += [
'elf.cpp',
'elfhack.cpp',
]
HostProgram('elfhack')
NO_PGO = True
+
+COMPILE_FLAGS['OS_CXXFLAGS'] = [
+ f for f in COMPILE_FLAGS['OS_CXXFLAGS'] if f != '-fno-exceptions'
+] + ['-fexceptions']
+