Skip to content

Commit

Permalink
Merge #30074: contrib: use ENV flags in get_arch
Browse files Browse the repository at this point in the history
b59a027 contrib: drop dead get_machine from test sym check (fanquake)
e6aba46 contrib: use env_flags in get_arch (fanquake)

Pull request description:

  This isn't an issue right now (because the get_arch check is simple), but becomes one as soon as we want to use `lld` for linking, and need LDFLAGS (otherwise we call `ld` and fail, see it's usage in #21778). So I've split this out for review. It also makes sense to use the same flags for all compilation in these checks.

  Also drops some dead code in test-symbol-check.

ACKs for top commit:
  TheCharlatan:
    ACK b59a027

Tree-SHA512: d8afc4144815369aae63cf6dc6e983af46f208c7043d6ea5c9c811152649c256a8e67eb6864ea9d385d87b6b049fece07710a84b90da325da7fc3f05efcaacd6
  • Loading branch information
fanquake committed May 15, 2024
2 parents f5fc319 + b59a027 commit 695d801
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 7 additions & 5 deletions contrib/devtools/test-security-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ def clean_files(source, executable):
os.remove(source)
os.remove(executable)

def call_security_check(cc: str, source: str, executable: str, options) -> tuple:
def env_flags() -> list[str]:
# This should behave the same as AC_TRY_LINK, so arrange well-known flags
# in the same order as autoconf would.
#
# See the definitions for ac_link in autoconf's lib/autoconf/c.m4 file for
# reference.
env_flags: list[str] = []
flags: list[str] = []
for var in ['CFLAGS', 'CPPFLAGS', 'LDFLAGS']:
env_flags += filter(None, os.environ.get(var, '').split(' '))
flags += filter(None, os.environ.get(var, '').split(' '))
return flags

subprocess.run([*cc,source,'-o',executable] + env_flags + options, check=True)
def call_security_check(cc: str, source: str, executable: str, options) -> tuple:
subprocess.run([*cc,source,'-o',executable] + env_flags() + options, check=True)
p = subprocess.run([os.path.join(os.path.dirname(__file__), 'security-check.py'), executable], stdout=subprocess.PIPE, text=True)
return (p.returncode, p.stdout.rstrip())

def get_arch(cc, source, executable):
subprocess.run([*cc, source, '-o', executable], check=True)
subprocess.run([*cc, source, '-o', executable] + env_flags(), check=True)
binary = lief.parse(executable)
arch = binary.abstract.header.architecture
os.remove(executable)
Expand Down
4 changes: 0 additions & 4 deletions contrib/devtools/test-symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def call_symbol_check(cc: list[str], source, executable, options):
os.remove(executable)
return (p.returncode, p.stdout.rstrip())

def get_machine(cc: list[str]):
p = subprocess.run([*cc,'-dumpmachine'], stdout=subprocess.PIPE, text=True)
return p.stdout.rstrip()

class TestSymbolChecks(unittest.TestCase):
def test_ELF(self):
source = 'test1.c'
Expand Down

0 comments on commit 695d801

Please sign in to comment.