Skip to content

Commit b5b9a9b

Browse files
committed
Don't pass -Xlinker flags to clang when compiling
This avoids a warning about unused linker flags.
1 parent 9e37a10 commit b5b9a9b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

emcc.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ def phase_compile_inputs(options, state, newargs, input_files):
949949
compiler.insert(0, config.COMPILER_WRAPPER)
950950

951951
compile_args = newargs
952+
952953
system_libs.ensure_sysroot()
953954

954955
def get_language_mode(args):
@@ -1016,13 +1017,25 @@ def get_clang_command_asm():
10161017

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

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

1025-
compile_args = [a for a in compile_args if a and not is_link_flag(a)]
1027+
skip = False
1028+
for arg in newargs:
1029+
if skip:
1030+
skip = False
1031+
continue
1032+
if is_link_flag(arg):
1033+
continue
1034+
if arg == '-Xlinker':
1035+
skip = True
1036+
continue
1037+
compile_args.append(arg)
1038+
10261039
linker_inputs = []
10271040
seen_names = {}
10281041

test/test_other.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11946,6 +11946,11 @@ def test_linker_flags_unused(self):
1194611946
err = self.run_process([EMCC, test_file('hello_world.c'), '-c', '-lbar'], stderr=PIPE).stderr
1194711947
self.assertContained("warning: -lbar: 'linker' input unused [-Wunused-command-line-argument]", err)
1194811948

11949+
# Check that we don't see these input unused errors for linker flags (i.e. ensure that we
11950+
# don't pass them to clang when compiling internally.
11951+
err = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-static', '-Xlinker', '-static'], stderr=PIPE).stderr
11952+
self.assertNotContained("input unused", err)
11953+
1194911954
def test_linker_input_unused(self):
1195011955
self.run_process([EMCC, '-c', test_file('hello_world.c')])
1195111956
err = self.run_process([EMCC, 'hello_world.o', '-c', '-o', 'out.o'], stderr=PIPE).stderr

0 commit comments

Comments
 (0)