Skip to content

Commit 610a8a8

Browse files
dongcarlfanquake
authored andcommitted
test-*-check: Pass in *FLAGS and compile with them
These test-*-check scripts should compile "test" binaries in a way that is as close to what autotools would do, since the goal is to make sure that if we run the *-check script, they can correctly detect flaws in binaries which are compiled by our autotools-based system. Therefore, we should emulate what happens when the binary is linked in autotools, meaning that for C binaries, we need to supply the CFLAGS, CPPFLAGS, and LDFLAGS flags in that order. Note to future developers: perhaps it'd be nice to have these test-*-check scripts be part of configure.ac to avoid having to manually replicate autoconf-like behaviour every time we find a discrepancy. Of course, that would also mean you'd have to write more m4...
1 parent 1790a8d commit 610a8a8

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Makefile.am

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ clean-local: clean-docs
367367

368368
test-security-check:
369369
if TARGET_DARWIN
370-
$(AM_V_at) CC='$(CC)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_MACHO
371-
$(AM_V_at) CC='$(CC)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_MACHO
370+
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_MACHO
371+
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_MACHO
372372
endif
373373
if TARGET_WINDOWS
374-
$(AM_V_at) CC='$(CC)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_PE
375-
$(AM_V_at) CC='$(CC)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_PE
374+
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_PE
375+
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_PE
376376
endif
377377
if TARGET_LINUX
378-
$(AM_V_at) CC='$(CC)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_ELF
379-
$(AM_V_at) CC='$(CC)' CPPFILT='$(CPPFILT)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_ELF
378+
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_ELF
379+
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' CPPFILT='$(CPPFILT)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_ELF
380380
endif

contrib/devtools/test-security-check.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'''
88
import os
99
import subprocess
10+
from typing import List
1011
import unittest
1112

1213
from utils import determine_wellknown_cmd
@@ -27,7 +28,16 @@ def clean_files(source, executable):
2728
os.remove(executable)
2829

2930
def call_security_check(cc, source, executable, options):
30-
subprocess.run([*cc,source,'-o',executable] + options, check=True)
31+
# This should behave the same as AC_TRY_LINK, so arrange well-known flags
32+
# in the same order as autoconf would.
33+
#
34+
# See the definitions for ac_link in autoconf's lib/autoconf/c.m4 file for
35+
# reference.
36+
env_flags: List[str] = []
37+
for var in ['CFLAGS', 'CPPFLAGS', 'LDFLAGS']:
38+
env_flags += filter(None, os.environ.get(var, '').split(' '))
39+
40+
subprocess.run([*cc,source,'-o',executable] + env_flags + options, check=True)
3141
p = subprocess.run(['./contrib/devtools/security-check.py',executable], stdout=subprocess.PIPE, universal_newlines=True)
3242
return (p.returncode, p.stdout.rstrip())
3343

contrib/devtools/test-symbol-check.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
from utils import determine_wellknown_cmd
1414

1515
def call_symbol_check(cc: List[str], source, executable, options):
16-
subprocess.run([*cc,source,'-o',executable] + options, check=True)
16+
# This should behave the same as AC_TRY_LINK, so arrange well-known flags
17+
# in the same order as autoconf would.
18+
#
19+
# See the definitions for ac_link in autoconf's lib/autoconf/c.m4 file for
20+
# reference.
21+
env_flags: List[str] = []
22+
for var in ['CFLAGS', 'CPPFLAGS', 'LDFLAGS']:
23+
env_flags += filter(None, os.environ.get(var, '').split(' '))
24+
25+
subprocess.run([*cc,source,'-o',executable] + env_flags + options, check=True)
1726
p = subprocess.run(['./contrib/devtools/symbol-check.py',executable], stdout=subprocess.PIPE, universal_newlines=True)
1827
os.remove(source)
1928
os.remove(executable)

0 commit comments

Comments
 (0)