Skip to content

Commit f31bd74

Browse files
authored
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.
1 parent 1eed2ff commit f31bd74

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ See docs/process.md for more on how version tagging works.
2121
3.1.52 (in development)
2222
-----------------------
2323
- The `--default-obj-ext` command line flag was removed. (#20917)
24+
- emcc will now treat `.bc` files as source files. These means that will get
25+
compiled by clang before being passed to the linker. This matches the
26+
behaviour of clang. (#20922)
2427

2528
3.1.51 - 12/13/23
2629
-----------------

emcc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
SPECIAL_ENDINGLESS_FILENAMES = [os.devnull]
6666
C_ENDINGS += SPECIAL_ENDINGLESS_FILENAMES # consider the special endingless filenames like /dev/null to be C
6767

68-
SOURCE_ENDINGS = C_ENDINGS + CXX_ENDINGS + OBJC_ENDINGS + OBJCXX_ENDINGS + ['.ll', '.S']
68+
SOURCE_ENDINGS = C_ENDINGS + CXX_ENDINGS + OBJC_ENDINGS + OBJCXX_ENDINGS + ['.bc', '.ll', '.S']
6969
ASSEMBLY_ENDINGS = ['.s']
7070
HEADER_ENDINGS = ['.h', '.hxx', '.hpp', '.hh', '.H', '.HXX', '.HPP', '.HH']
7171

test/test_other.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ def test_dumpmachine(self):
463463
'c': [EMCC, '.c'],
464464
'cxx': [EMXX, '.cpp']})
465465
def test_emcc_2(self, compiler, suffix):
466-
# emcc src.cpp -c and emcc -c src.cpp -o src.[o|bc|so] ==> should always give an object file
467-
for args in [[], ['-o', 'src.o'], ['-o', 'src.bc'], ['-o', 'src.so']]:
466+
# emcc src.cpp -c and emcc -c src.cpp -o src.[o|foo|so] ==> should always give an object file
467+
for args in [[], ['-o', 'src.o'], ['-o', 'src.foo'], ['-o', 'src.so']]:
468468
print('args:', args)
469469
target = args[1] if len(args) == 2 else 'hello_world.o'
470470
self.clear()
@@ -475,9 +475,6 @@ def test_emcc_2(self, compiler, suffix):
475475
# we also expect to have the '__original_main' wrapper and __main_void alias.
476476
# TODO(sbc): Should be 4 once https://reviews.llvm.org/D75277 lands
477477
self.assertIn(len(syms['defs']), (2, 3))
478-
if target == 'js': # make sure emcc can recognize the target as a bitcode file
479-
shutil.move(target, target + '.bc')
480-
target += '.bc'
481478
self.run_process([compiler, target, '-o', target + '.js'])
482479
self.assertContained('hello, world!', self.run_js(target + '.js'))
483480

@@ -4600,9 +4597,8 @@ def test_bad_triple(self):
46004597
# native building on CI may not always work well
46014598
create_file('minimal.c', 'int main() { return 0; }')
46024599
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())
4603-
# wasm backend will hard fail where as fastcomp only warns
4604-
err = self.expect_fail([EMCC, 'a.bc'])
4605-
self.assertContained('machine type must be wasm32', err)
4600+
err = self.expect_fail([EMCC, '-Werror', 'a.bc'])
4601+
self.assertContained('error: overriding the module target triple with wasm32-unknown-emscripten [-Werror,-Woverride-module]', err)
46064602

46074603
def test_valid_abspath(self):
46084604
# Test whether abspath warning appears
@@ -12623,18 +12619,10 @@ def test_no_main_with_PROXY_TO_PTHREAD(self):
1262312619
self.assertContained('crt1_proxy_main.o: undefined symbol: main', err)
1262412620

1262512621
def test_archive_bad_extension(self):
12626-
# Regression test for https://github.com/emscripten-core/emscripten/issues/14012
12627-
# where llvm_nm_multiple would be confused by archives names like object files.
12628-
create_file('main.c', '''
12629-
#include <sys/socket.h>
12630-
int main() {
12631-
return (int)(long)&accept;
12632-
}
12633-
''')
12634-
12635-
self.run_process([EMCC, '-c', 'main.c'])
12636-
self.run_process([EMAR, 'crs', 'libtest.bc', 'main.o'])
12637-
self.run_process([EMCC, 'libtest.bc', 'libtest.bc'])
12622+
self.run_process([EMCC, '-c', test_file('hello_world.c')])
12623+
self.run_process([EMAR, 'crs', 'libtest.bc', 'hello_world.o'])
12624+
err = self.expect_fail([EMCC, 'libtest.bc'])
12625+
self.assertContained('libtest.bc:1:2: error: expected integer', err)
1263812626

1263912627
def test_split_dwarf_implicit_compile(self):
1264012628
# Verify that the dwo file is generated in the current working directory, even when implicitly

0 commit comments

Comments
 (0)