Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on missing linker flags #23461

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,11 @@ def phase_setup(options, state, newargs):
if arg in CLANG_FLAGS_WITH_ARGS:
skip = True

def get_next_arg():
if len(newargs) <= i + 1:
exit_with_error(f"option '{arg}' requires an argument")
return newargs[i + 1]

if not arg.startswith('-'):
# we already removed -o <target>, so all these should be inputs
newargs[i] = ''
Expand All @@ -797,7 +802,7 @@ def phase_setup(options, state, newargs):
state.add_link_flag(i, arg)
elif arg == '-z':
state.add_link_flag(i, newargs[i])
state.add_link_flag(i + 1, newargs[i + 1])
state.add_link_flag(i + 1, get_next_arg())
elif arg.startswith('-z'):
state.add_link_flag(i, newargs[i])
elif arg.startswith('--js-library='):
Expand All @@ -810,7 +815,7 @@ def phase_setup(options, state, newargs):
for flag_index, flag in enumerate(link_flags_to_add):
state.add_link_flag(i + float(flag_index) / len(link_flags_to_add), flag)
elif arg == '-Xlinker':
state.add_link_flag(i + 1, newargs[i + 1])
state.add_link_flag(i + 1, get_next_arg())
elif arg == '-s':
state.add_link_flag(i, newargs[i])
elif arg == '-':
Expand Down Expand Up @@ -1154,7 +1159,7 @@ def check_arg(name):
return True
if arg == name:
if len(newargs) <= i + 1:
exit_with_error("option '%s' requires an argument" % arg)
exit_with_error(f"option '{arg}' requires an argument")
arg_value = newargs[i + 1]
newargs[i] = ''
newargs[i + 1] = ''
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ lint.ignore = [
"PLW2901",
]
lint.per-file-ignores."emrun.py" = [ "PLE0704" ]
lint.mccabe.max-complexity = 49 # Recommended: 10
lint.mccabe.max-complexity = 51 # Recommended: 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂😅

lint.pylint.allow-magic-value-types = [
"bytes",
"float",
Expand Down
4 changes: 4 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -12300,6 +12300,10 @@ def test_linker_flags_unused(self):
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_flags_missing(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-Xlinker'])
self.assertContained("emcc: error: option '-Xlinker' requires an argument", 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
Loading