Skip to content

FIX Turn off settings.LTO if -fno-lto is passed #20309

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

Merged
merged 4 commits into from
Sep 22, 2023
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
2 changes: 2 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,8 @@ def consume_arg_file():
settings.LTO = arg.split('=')[1]
else:
settings.LTO = 'full'
elif arg == "-fno-lto":
settings.LTO = 0
elif check_arg('--llvm-lto'):
logger.warning('--llvm-lto ignored when using llvm backend')
consume_arg()
Expand Down
18 changes: 18 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -11148,6 +11148,24 @@ def test_setjmp_emulated_casts(self):
''')
self.do_runf('src.c', 'ok\ndone\n', emcc_args=['-sEMULATE_FUNCTION_POINTER_CASTS'])

def test_no_lto(self):
# This used to fail because settings.LTO didn't reflect `-fno-lto`.
# See bug https://github.com/emscripten-core/emscripten/issues/20308
create_file('src.c', r'''
#include <stdio.h>
#include <setjmp.h>
int main() {
jmp_buf jb;
if (!setjmp(jb)) {
printf("ok\n");
longjmp(jb, 1);
} else {
printf("done\n");
}
}
''')
self.do_runf('src.c', 'ok\ndone\n', emcc_args=['-flto', '-fno-lto'])

def test_missing_stdlibs(self):
# Certain standard libraries are expected to be useable via -l flags but
# don't actually exist in our standard library path. Make sure we don't
Expand Down