Skip to content

Commit

Permalink
Treat .bc files as source files (#20922)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 authored Dec 14, 2023
1 parent 1eed2ff commit f31bd74
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------
Expand Down
2 changes: 1 addition & 1 deletion emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
28 changes: 8 additions & 20 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <sys/socket.h>
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
Expand Down

0 comments on commit f31bd74

Please sign in to comment.