Bug 1403346 - Implement cflags filtering for elfhack in mozbuild COMPILE_FLAGS draft
authorChris Manchester <cmanchester@mozilla.com>
Wed, 25 Oct 2017 15:12:10 -0700
changeset 686529 904f55ece8c21a4e427cb58b1c0067ce7e208474
parent 686528 fbb72df6b41aa33fe1d363949907a123b10a4961
child 686530 23cf0b3f60938c9b6efc52dfaf3c77a717be201b
push id86198
push userbmo:cmanchester@mozilla.com
push dateWed, 25 Oct 2017 22:13:37 +0000
bugs1403346
milestone58.0a1
Bug 1403346 - Implement cflags filtering for elfhack in mozbuild COMPILE_FLAGS MozReview-Commit-ID: GO2mqMjHuHd
build/unix/elfhack/Makefile.in
build/unix/elfhack/inject/Makefile.in
build/unix/elfhack/inject/moz.build
build/unix/elfhack/moz.build
--- 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']
+