From f31bd74dba9fb108cdbdbb913afc06616b920fd4 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 14 Dec 2023 14:50:59 -0800 Subject: [PATCH] Treat .bc files as source files (#20922) This matches the behaviour of clang, and means that `.ll` and `.bc` files get treated similarly. The modified test here no longer applies since we no longer run `nm` on linker inputs. --- ChangeLog.md | 3 +++ emcc.py | 2 +- test/test_other.py | 28 ++++++++-------------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 6051e28c21e59..eca32557c83f2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -21,6 +21,9 @@ See docs/process.md for more on how version tagging works. 3.1.52 (in development) ----------------------- - The `--default-obj-ext` command line flag was removed. (#20917) +- emcc will now treat `.bc` files as source files. These means that will get + compiled by clang before being passed to the linker. This matches the + behaviour of clang. (#20922) 3.1.51 - 12/13/23 ----------------- diff --git a/emcc.py b/emcc.py index 41237abf3178a..5b8652ef59dcc 100644 --- a/emcc.py +++ b/emcc.py @@ -65,7 +65,7 @@ SPECIAL_ENDINGLESS_FILENAMES = [os.devnull] C_ENDINGS += SPECIAL_ENDINGLESS_FILENAMES # consider the special endingless filenames like /dev/null to be C -SOURCE_ENDINGS = C_ENDINGS + CXX_ENDINGS + OBJC_ENDINGS + OBJCXX_ENDINGS + ['.ll', '.S'] +SOURCE_ENDINGS = C_ENDINGS + CXX_ENDINGS + OBJC_ENDINGS + OBJCXX_ENDINGS + ['.bc', '.ll', '.S'] ASSEMBLY_ENDINGS = ['.s'] HEADER_ENDINGS = ['.h', '.hxx', '.hpp', '.hh', '.H', '.HXX', '.HPP', '.HH'] diff --git a/test/test_other.py b/test/test_other.py index 626a3ab1da616..d7054a197e033 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -463,8 +463,8 @@ def test_dumpmachine(self): 'c': [EMCC, '.c'], 'cxx': [EMXX, '.cpp']}) def test_emcc_2(self, compiler, suffix): - # emcc src.cpp -c and emcc -c src.cpp -o src.[o|bc|so] ==> should always give an object file - for args in [[], ['-o', 'src.o'], ['-o', 'src.bc'], ['-o', 'src.so']]: + # emcc src.cpp -c and emcc -c src.cpp -o src.[o|foo|so] ==> should always give an object file + for args in [[], ['-o', 'src.o'], ['-o', 'src.foo'], ['-o', 'src.so']]: print('args:', args) target = args[1] if len(args) == 2 else 'hello_world.o' self.clear() @@ -475,9 +475,6 @@ def test_emcc_2(self, compiler, suffix): # we also expect to have the '__original_main' wrapper and __main_void alias. # TODO(sbc): Should be 4 once https://reviews.llvm.org/D75277 lands self.assertIn(len(syms['defs']), (2, 3)) - if target == 'js': # make sure emcc can recognize the target as a bitcode file - shutil.move(target, target + '.bc') - target += '.bc' self.run_process([compiler, target, '-o', target + '.js']) self.assertContained('hello, world!', self.run_js(target + '.js')) @@ -4600,9 +4597,8 @@ def test_bad_triple(self): # native building on CI may not always work well create_file('minimal.c', 'int main() { return 0; }') self.run_process([CLANG_CC, 'minimal.c', '-target', 'x86_64-linux', '-c', '-emit-llvm', '-o', 'a.bc'] + clang_native.get_clang_native_args(), env=clang_native.get_clang_native_env()) - # wasm backend will hard fail where as fastcomp only warns - err = self.expect_fail([EMCC, 'a.bc']) - self.assertContained('machine type must be wasm32', err) + err = self.expect_fail([EMCC, '-Werror', 'a.bc']) + self.assertContained('error: overriding the module target triple with wasm32-unknown-emscripten [-Werror,-Woverride-module]', err) def test_valid_abspath(self): # Test whether abspath warning appears @@ -12623,18 +12619,10 @@ def test_no_main_with_PROXY_TO_PTHREAD(self): self.assertContained('crt1_proxy_main.o: undefined symbol: main', err) def test_archive_bad_extension(self): - # Regression test for https://github.com/emscripten-core/emscripten/issues/14012 - # where llvm_nm_multiple would be confused by archives names like object files. - create_file('main.c', ''' - #include - int main() { - return (int)(long)&accept; - } - ''') - - self.run_process([EMCC, '-c', 'main.c']) - self.run_process([EMAR, 'crs', 'libtest.bc', 'main.o']) - self.run_process([EMCC, 'libtest.bc', 'libtest.bc']) + self.run_process([EMCC, '-c', test_file('hello_world.c')]) + self.run_process([EMAR, 'crs', 'libtest.bc', 'hello_world.o']) + err = self.expect_fail([EMCC, 'libtest.bc']) + self.assertContained('libtest.bc:1:2: error: expected integer', err) def test_split_dwarf_implicit_compile(self): # Verify that the dwo file is generated in the current working directory, even when implicitly