Skip to content

Commit 6956a0c

Browse files
authored
Don't pass -Xlinker flags to clang when compiling (#22716)
This avoids a warning about unused linker flags.
1 parent cd60934 commit 6956a0c

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

emcc.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,28 @@ def get_clang_output_extension(state):
937937
return '.o'
938938

939939

940+
def filter_out_link_flags(args):
941+
rtn = []
942+
943+
def is_link_flag(flag):
944+
if flag in ('-nostdlib', '-nostartfiles', '-nolibc', '-nodefaultlibs', '-s'):
945+
return True
946+
return flag.startswith(('-l', '-L', '-Wl,', '-z'))
947+
948+
skip = False
949+
for arg in args:
950+
if skip:
951+
skip = False
952+
continue
953+
if is_link_flag(arg):
954+
continue
955+
if arg == '-Xlinker':
956+
skip = True
957+
continue
958+
rtn.append(arg)
959+
return rtn
960+
961+
940962
@ToolchainProfiler.profile_block('compile inputs')
941963
def phase_compile_inputs(options, state, newargs, input_files):
942964
if shared.run_via_emxx:
@@ -1016,13 +1038,7 @@ def get_clang_command_asm():
10161038

10171039
# In COMPILE_AND_LINK we need to compile source files too, but we also need to
10181040
# filter out the link flags
1019-
1020-
def is_link_flag(flag):
1021-
if flag in ('-nostdlib', '-nostartfiles', '-nolibc', '-nodefaultlibs', '-s'):
1022-
return True
1023-
return flag.startswith(('-l', '-L', '-Wl,', '-z'))
1024-
1025-
compile_args = [a for a in compile_args if a and not is_link_flag(a)]
1041+
compile_args = filter_out_link_flags(compile_args)
10261042
linker_inputs = []
10271043
seen_names = {}
10281044

test/test_other.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11946,6 +11946,12 @@ 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 when
11950+
# compiling and linking in single step (i.e. ensure that we don't pass them to clang when
11951+
# compiling internally).
11952+
err = self.run_process([EMCC, test_file('hello_world.c'), '-Wl,-static', '-Xlinker', '-static'], stderr=PIPE).stderr
11953+
self.assertNotContained("input unused", err)
11954+
1194911955
def test_linker_input_unused(self):
1195011956
self.run_process([EMCC, '-c', test_file('hello_world.c')])
1195111957
err = self.run_process([EMCC, 'hello_world.o', '-c', '-o', 'out.o'], stderr=PIPE).stderr

0 commit comments

Comments
 (0)