Skip to content

Commit c25daa4

Browse files
committed
Deprecate RUNTIME_LINKED_LIBS setting. NFC
Its better to simply list dynamic library dependencies directly on the command line. Handle the deprecated option by simply added the list of libraries to the command line. This means we no longer need to modify the dylink section after linking since the linker will inject all the needed dynamic libraries that it sees on the command line.
1 parent dff3336 commit c25daa4

File tree

5 files changed

+45
-99
lines changed

5 files changed

+45
-99
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
Current Trunk
2222
-------------
23+
- The `RUNTIME_LINKED_LIBS` setting is now deprecated. It's better to simply
24+
list dynamic library dependencies directly on the command line.
25+
2326
2.0.18: 04/23/2021
2427
------------------
2528
- The `makeBigInt` function was removed from the emscripten runtime since it

emcc.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,45 @@ def uniquename(name):
10611061
explicit_settings_changes, newargs = parse_s_args(newargs)
10621062
settings_changes += explicit_settings_changes
10631063

1064+
settings_map = {}
1065+
for s in settings_changes:
1066+
key, value = s.split('=', 1)
1067+
settings_map[key] = value
1068+
1069+
# Libraries are searched before settings_changes are applied, so apply the
1070+
# value for STRICT from command line already now.
1071+
1072+
strict_cmdline = settings_map.get('STRICT')
1073+
if strict_cmdline:
1074+
settings.STRICT = int(strict_cmdline)
1075+
1076+
# Apply optimization level settings
1077+
1078+
if settings.OPT_LEVEL >= 1:
1079+
settings.ASSERTIONS = 0
1080+
if settings.SHRINK_LEVEL >= 2:
1081+
settings.EVAL_CTORS = 1
1082+
1083+
# For users that opt out of WARN_ON_UNDEFINED_SYMBOLS we assume they also
1084+
# want to opt out of ERROR_ON_UNDEFINED_SYMBOLS.
1085+
if settings_map.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
1086+
settings.ERROR_ON_UNDEFINED_SYMBOLS = 0
1087+
1088+
if settings.MINIMAL_RUNTIME or settings_map.get('MINIMAL_RUNTIME') in ('1', '2'):
1089+
# Remove the default exported functions 'malloc', 'free', etc. those should only be linked in if used
1090+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE = []
1091+
1092+
# Apply -s settings in newargs here (after optimization levels, so they can override them)
1093+
apply_settings(settings_map)
1094+
1095+
if settings.EXTRA_EXPORTED_RUNTIME_METHODS:
1096+
diagnostics.warning('deprecated', 'EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead')
1097+
settings.EXPORTED_RUNTIME_METHODS += settings.EXTRA_EXPORTED_RUNTIME_METHODS
1098+
1099+
if settings.RUNTIME_LINKED_LIBS:
1100+
diagnostics.warning('deprecated', 'RUNTIME_LINKED_LIBS is deprecated; you can simply list the libraries directly on the commandline now')
1101+
newargs += settings.RUNTIME_LINKED_LIBS
1102+
10641103
# Find input files
10651104

10661105
# These three arrays are used to store arguments of different types for
@@ -1165,37 +1204,6 @@ def add_link_flag(i, f):
11651204

11661205
newargs = [a for a in newargs if a]
11671206

1168-
settings_map = {}
1169-
for s in settings_changes:
1170-
key, value = s.split('=', 1)
1171-
settings_map[key] = value
1172-
1173-
# Libraries are searched before settings_changes are applied, so apply the
1174-
# value for STRICT from command line already now.
1175-
1176-
strict_cmdline = settings_map.get('STRICT')
1177-
if strict_cmdline:
1178-
settings.STRICT = int(strict_cmdline)
1179-
1180-
# Apply optimization level settings
1181-
1182-
if settings.OPT_LEVEL >= 1:
1183-
settings.ASSERTIONS = 0
1184-
if settings.SHRINK_LEVEL >= 2:
1185-
settings.EVAL_CTORS = 1
1186-
1187-
# For users that opt out of WARN_ON_UNDEFINED_SYMBOLS we assume they also
1188-
# want to opt out of ERROR_ON_UNDEFINED_SYMBOLS.
1189-
if settings_map.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
1190-
settings.ERROR_ON_UNDEFINED_SYMBOLS = 0
1191-
1192-
if settings.MINIMAL_RUNTIME or settings_map.get('MINIMAL_RUNTIME') in ('1', '2'):
1193-
# Remove the default exported functions 'malloc', 'free', etc. those should only be linked in if used
1194-
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE = []
1195-
1196-
# Apply -s settings in newargs here (after optimization levels, so they can override them)
1197-
apply_settings(settings_map)
1198-
11991207
specified_target = options.output_file
12001208

12011209
if os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in args:
@@ -1227,10 +1235,6 @@ def add_link_flag(i, f):
12271235

12281236
settings.TARGET_BASENAME = target_basename = unsuffixed_basename(target)
12291237

1230-
if settings.EXTRA_EXPORTED_RUNTIME_METHODS:
1231-
diagnostics.warning('deprecated', 'EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead')
1232-
settings.EXPORTED_RUNTIME_METHODS += settings.EXTRA_EXPORTED_RUNTIME_METHODS
1233-
12341238
final_suffix = get_file_suffix(target)
12351239

12361240
if has_dash_c or has_dash_S or has_dash_E or '-M' in newargs or '-MM' in newargs:
@@ -2925,10 +2929,6 @@ def do_binaryen(target, options, wasm_target):
29252929

29262930
# after generating the wasm, do some final operations
29272931

2928-
# Add extra dylibs if needed.
2929-
if settings.RUNTIME_LINKED_LIBS:
2930-
webassembly.update_dylink_section(wasm_target, settings.RUNTIME_LINKED_LIBS)
2931-
29322932
if settings.EMIT_EMSCRIPTEN_METADATA:
29332933
diagnostics.warning('deprecated', 'We hope to remove support for EMIT_EMSCRIPTEN_METADATA. See https://github.com/emscripten-core/emscripten/issues/12231')
29342934
webassembly.add_emscripten_metadata(wasm_target)

src/settings.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,7 @@ var MAIN_MODULE = 0;
973973
// [compile+link]
974974
var SIDE_MODULE = 0;
975975

976-
// If this is a shared object (MAIN_MODULE == 1 || SIDE_MODULE == 1), then we
977-
// will link these at runtime. They must have been built with SIDE_MODULE == 1.
978-
// In most cases it is simpler to pass the filenames directly on the commandline
979-
// instead.
976+
// Deprecated, list shared libraries directly on the command line instead.
980977
// [link]
981978
var RUNTIME_LINKED_LIBS = [];
982979

tests/test_other.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5430,7 +5430,8 @@ def test_RUNTIME_LINKED_LIBS(self):
54305430
self.run_process([EMCC, '-O2', 'main.c', '-s', 'MAIN_MODULE', '-o', 'main.js', 'side.wasm'])
54315431
self.run_js('main.js')
54325432

5433-
self.run_process([EMCC, '-O2', 'main.c', '-s', 'MAIN_MODULE', '-o', 'main2.js', '-s', 'RUNTIME_LINKED_LIBS=side.wasm'])
5433+
err = self.run_process([EMCC, '-O2', 'main.c', '-s', 'MAIN_MODULE', '-o', 'main2.js', '-s', 'RUNTIME_LINKED_LIBS=side.wasm'], stderr=PIPE).stderr
5434+
self.assertContained('emcc: warning: RUNTIME_LINKED_LIBS is deprecated', err)
54345435
self.run_js('main2.js')
54355436

54365437
self.assertBinaryEqual('main.wasm', 'main2.wasm')

tools/webassembly.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -258,58 +258,3 @@ def get_imports(wasm_file):
258258
assert False
259259

260260
return imports
261-
262-
263-
def update_dylink_section(wasm_file, extra_dynlibs):
264-
# A wasm shared library has a special "dylink" section, see tools-conventions repo.
265-
# This function updates this section, adding extra dynamic library dependencies.
266-
267-
mem_size, mem_align, table_size, table_align, section_end, needed = parse_dylink_section(wasm_file)
268-
269-
section_name = b'\06dylink' # section name, including prefixed size
270-
contents = (toLEB(mem_size) + toLEB(mem_align) +
271-
toLEB(table_size) + toLEB(0))
272-
273-
# we extend "dylink" section with information about which shared libraries
274-
# our shared library needs. This is similar to DT_NEEDED entries in ELF.
275-
#
276-
# In theory we could avoid doing this, since every import in wasm has
277-
# "module" and "name" attributes, but currently emscripten almost always
278-
# uses just "env" for "module". This way we have to embed information about
279-
# required libraries for the dynamic linker somewhere, and "dylink" section
280-
# seems to be the most relevant place.
281-
#
282-
# Binary format of the extension:
283-
#
284-
# needed_dynlibs_count varuint32 ; number of needed shared libraries
285-
# needed_dynlibs_entries dynlib_entry* ; repeated dynamic library entries as described below
286-
#
287-
# dynlib_entry:
288-
#
289-
# dynlib_name_len varuint32 ; length of dynlib_name_str in bytes
290-
# dynlib_name_str bytes ; name of a needed dynamic library: valid UTF-8 byte sequence
291-
#
292-
# a proposal has been filed to include the extension into "dylink" specification:
293-
# https://github.com/WebAssembly/tool-conventions/pull/77
294-
needed += extra_dynlibs
295-
contents += toLEB(len(needed))
296-
for dyn_needed in needed:
297-
dyn_needed = dyn_needed.encode('utf-8')
298-
contents += toLEB(len(dyn_needed))
299-
contents += dyn_needed
300-
301-
orig = open(wasm_file, 'rb').read()
302-
file_header = orig[:8]
303-
file_remainder = orig[section_end:]
304-
305-
section_size = len(section_name) + len(contents)
306-
with open(wasm_file, 'wb') as f:
307-
# copy magic number and version
308-
f.write(file_header)
309-
# write the special section
310-
f.write(b'\0') # user section is code 0
311-
f.write(toLEB(section_size))
312-
f.write(section_name)
313-
f.write(contents)
314-
# copy rest of binary
315-
f.write(file_remainder)

0 commit comments

Comments
 (0)