Bug 1302891 - Part 4 - Disable CFI for binaries that are compiled with -fno-lto; r?glandium draft
authorEnes Goktas <egoktas@mozilla.com>
Thu, 15 Sep 2016 13:26:39 -0700
changeset 418764 766e6fbdad9d4a0c75820bf848befcf77f4025a7
parent 418763 412f6b84519a3985fb3a42a78b2b64383e7f9077
child 418765 05d15bd50f1c4b71923ae0987ea022e72dafa3b1
push id30776
push userbmo:enes.goktas@gmail.com
push dateThu, 29 Sep 2016 05:44:28 +0000
reviewersglandium
bugs1302891
milestone52.0a1
Bug 1302891 - Part 4 - Disable CFI for binaries that are compiled with -fno-lto; r?glandium Also add -fno-lto to flags of dummy.c to fix elfhack test. The compilation of dummy.c with -flto was causing elfhack test to fail. MozReview-Commit-ID: BQ4J2Pt8yL7
build/unix/elfhack/moz.build
toolkit/library/StaticXULComponentsEnd/moz.build
toolkit/library/moz.build
--- a/build/unix/elfhack/moz.build
+++ b/build/unix/elfhack/moz.build
@@ -10,19 +10,27 @@ DIRS += ['inject']
 if not CONFIG['CROSS_COMPILE']:
     SOURCES += [
         'dummy.c',
         'test-array.c',
         'test-ctors.c',
     ]
 
     if '-flto' in CONFIG['OS_CFLAGS']:
+        SOURCES['dummy.c'].flags += ['-fno-lto']
         SOURCES['test-array.c'].flags += ['-fno-lto']
         SOURCES['test-ctors.c'].flags += ['-fno-lto']
 
+        # -fno-lto blocks -fsanitize=cfi, so we need to disable cfi
+        if '-fsanitize=cfi' in CONFIG['OS_CFLAGS']:
+            SOURCES['dummy.c'].flags += ['-fno-sanitize=cfi']
+            SOURCES['test-array.c'].flags += ['-fno-sanitize=cfi']
+            SOURCES['test-ctors.c'].flags += ['-fno-sanitize=cfi']
+
+
 HOST_SOURCES += [
     'elf.cpp',
     'elfhack.cpp',
 ]
 
 HostProgram('elfhack')
 
 NO_PGO = True
--- a/toolkit/library/StaticXULComponentsEnd/moz.build
+++ b/toolkit/library/StaticXULComponentsEnd/moz.build
@@ -5,11 +5,15 @@
 SOURCES += [
     'StaticXULComponentsEnd.cpp',
 ]
 
 # Don't let LTO reorder StaticXULComponentsStart.o.
 if '-flto' in CONFIG['OS_CXXFLAGS']:
     SOURCES['StaticXULComponentsEnd.cpp'].flags += ['-fno-lto']
 
+    # -fno-lto blocks -fsanitize=cfi, so we need to disable cfi
+    if '-fsanitize=cfi' in CONFIG['OS_CXXFLAGS']:
+        SOURCES['StaticXULComponentsEnd.cpp'].flags += ['-fno-sanitize=cfi']
+
 Library('StaticXULComponentsEnd')
 
 DEFINES['MOZILLA_INTERNAL_API'] = True
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -83,16 +83,20 @@ SOURCES += [
 # This, combined with the fact the file is first, makes the start pointer
 # it contains first in Windows PGO builds.
 SOURCES['StaticXULComponentsStart.cpp'].no_pgo = True
 
 # Don't let LTO reorder StaticXULComponentsStart.o.
 if '-flto' in CONFIG['OS_CXXFLAGS']:
     SOURCES['StaticXULComponentsStart.cpp'].flags += ['-fno-lto']
 
+    # -fno-lto blocks -fsanitize=cfi, so we need to disable cfi
+    if '-fsanitize=cfi' in CONFIG['OS_CXXFLAGS']:
+        SOURCES['StaticXULComponentsStart.cpp'].flags += ['-fno-sanitize=cfi']
+
 if CONFIG['OS_ARCH'] == 'WINNT':
     SOURCES += [
         'nsDllMain.cpp',
     ]
 
 LOCAL_INCLUDES += [
     '/config',
     # need widget/windows for resource.h (included from widget.rc)