make .a link groups work also when linking just to bitcode; fixes #2568
This commit is contained in:
Родитель
2f3f008141
Коммит
1c3412cccd
10
emcc
10
emcc
|
@ -1499,6 +1499,9 @@ try:
|
|||
#if DEBUG: shutil.copyfile(temp_file, os.path.join(TEMP_DIR, 'to_opt.bc') # useful when LLVM opt aborts
|
||||
shared.Building.llvm_opt(temp_file, llvm_opts)
|
||||
|
||||
# Decide what we will link
|
||||
linker_inputs = [val for _, val in sorted(temp_files + link_flags)]
|
||||
|
||||
# If we were just asked to generate bitcode, stop there
|
||||
if final_suffix not in JS_CONTAINING_SUFFIXES:
|
||||
if not specified_target:
|
||||
|
@ -1522,10 +1525,9 @@ try:
|
|||
assert len(original_input_files) == 1 or not has_dash_c, 'fatal error: cannot specify -o with -c with multiple files' + str(sys.argv) + ':' + str(original_input_files)
|
||||
# We have a specified target (-o <target>), which is not JavaScript or HTML, and
|
||||
# we have multiple files: Link them
|
||||
logging.debug('link: ' + str(temp_files) + specified_target)
|
||||
logging.debug('link: ' + str(linker_inputs) + specified_target)
|
||||
# Sort arg tuples and pass the extracted values to link.
|
||||
link_args = [f for (i, f) in sorted(temp_files)]
|
||||
shared.Building.link(link_args, specified_target)
|
||||
shared.Building.link(linker_inputs, specified_target)
|
||||
logging.debug('stopping at bitcode')
|
||||
exit(0)
|
||||
|
||||
|
@ -1547,7 +1549,7 @@ try:
|
|||
# First, combine the bitcode files if there are several. We must also link if we have a singleton .a
|
||||
if len(input_files) + len(extra_files_to_link) > 1 or \
|
||||
(not LEAVE_INPUTS_RAW and not (suffix(temp_files[0][1]) in BITCODE_ENDINGS or suffix(temp_files[0][1]) in DYNAMICLIB_ENDINGS) and shared.Building.is_ar(temp_files[0][1])):
|
||||
linker_inputs = [val for _, val in sorted(temp_files + link_flags)] + extra_files_to_link
|
||||
linker_inputs += extra_files_to_link
|
||||
logging.debug('linking: ' + str(linker_inputs))
|
||||
shared.Building.link(linker_inputs, in_temp(target_basename + '.bc'), force_archive_contents=len([temp for i, temp in temp_files if not temp.endswith(STATICLIB_ENDINGS)]) == 0)
|
||||
final = in_temp(target_basename + '.bc')
|
||||
|
|
|
@ -1046,7 +1046,7 @@ This pointer might make sense in another type signature: i: 0
|
|||
|
||||
self.assertContained('result: 62', run_js(os.path.join(self.get_dir(), 'a.out.js')))
|
||||
|
||||
def test_link_group_asserts(self):
|
||||
def test_link_group(self):
|
||||
lib_src_name = os.path.join(self.get_dir(), 'lib.c')
|
||||
open(lib_src_name, 'w').write('int x() { return 42; }')
|
||||
|
||||
|
@ -1078,6 +1078,29 @@ This pointer might make sense in another type signature: i: 0
|
|||
test(['-Wl,--end-group', lib_name, '-Wl,--start-group'], '--end-group without --start-group')
|
||||
test(['-Wl,--start-group', lib_name, '-Wl,--end-group'], None)
|
||||
|
||||
def test_link_group_bitcode(self):
|
||||
one = open('1.c', 'w').write(r'''
|
||||
int f(void);
|
||||
int main() {
|
||||
f();
|
||||
return 0;
|
||||
}
|
||||
''')
|
||||
two = open('2.c', 'w').write(r'''
|
||||
#include <stdio.h>
|
||||
int f() {
|
||||
printf("Hello\n");
|
||||
return 0;
|
||||
}
|
||||
''')
|
||||
|
||||
Popen([PYTHON, EMCC, '-o', '1.o', '1.c']).communicate()
|
||||
Popen([PYTHON, EMCC, '-o', '2.o', '2.c']).communicate()
|
||||
Popen([PYTHON, EMAR, 'crs', '2.a', '2.o']).communicate()
|
||||
Popen([PYTHON, EMCC, '-o', 'out.bc', '-Wl,--start-group', '2.a', '1.o', '-Wl,--end-group']).communicate()
|
||||
Popen([PYTHON, EMCC, 'out.bc']).communicate()
|
||||
self.assertContained('Hello', run_js('a.out.js'))
|
||||
|
||||
def test_circular_libs(self):
|
||||
def tmp_source(name, code):
|
||||
file_name = os.path.join(self.get_dir(), name)
|
||||
|
|
Загрузка…
Ссылка в новой задаче