Skip to content

Commit

Permalink
Don't pass -Xlinker flags to clang when compiling
Browse files Browse the repository at this point in the history
This avoids a warning about unused linker flags.
  • Loading branch information
sbc100 committed Oct 10, 2024
1 parent 9e37a10 commit b5b9a9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ def phase_compile_inputs(options, state, newargs, input_files):
compiler.insert(0, config.COMPILER_WRAPPER)

compile_args = newargs

system_libs.ensure_sysroot()

def get_language_mode(args):
Expand Down Expand Up @@ -1016,13 +1017,25 @@ def get_clang_command_asm():

# In COMPILE_AND_LINK we need to compile source files too, but we also need to
# filter out the link flags
compile_args = []

def is_link_flag(flag):
if flag in ('-nostdlib', '-nostartfiles', '-nolibc', '-nodefaultlibs', '-s'):
return True
return flag.startswith(('-l', '-L', '-Wl,', '-z'))

compile_args = [a for a in compile_args if a and not is_link_flag(a)]
skip = False
for arg in newargs:
if skip:
skip = False
continue
if is_link_flag(arg):
continue
if arg == '-Xlinker':
skip = True
continue
compile_args.append(arg)

linker_inputs = []
seen_names = {}

Expand Down
5 changes: 5 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -11946,6 +11946,11 @@ def test_linker_flags_unused(self):
err = self.run_process([EMCC, test_file('hello_world.c'), '-c', '-lbar'], stderr=PIPE).stderr
self.assertContained("warning: -lbar: 'linker' input unused [-Wunused-command-line-argument]", err)

# Check that we don't see these input unused errors for linker flags (i.e. ensure that we
# don't pass them to clang when compiling internally.
err = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-static', '-Xlinker', '-static'], stderr=PIPE).stderr
self.assertNotContained("input unused", err)

def test_linker_input_unused(self):
self.run_process([EMCC, '-c', test_file('hello_world.c')])
err = self.run_process([EMCC, 'hello_world.o', '-c', '-o', 'out.o'], stderr=PIPE).stderr
Expand Down

0 comments on commit b5b9a9b

Please sign in to comment.