Skip to content

Commit

Permalink
Remove code for automatically adding archive indexes
Browse files Browse the repository at this point in the history
Now that wasm-ld no longer requires and index this code is no longer
needed.
  • Loading branch information
sbc100 committed Jan 20, 2024
1 parent 88fe106 commit 88a3afc
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 60 deletions.
9 changes: 1 addition & 8 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,6 @@ var LINKABLE = false;
// - IGNORE_MISSING_MAIN is disabled.
// - AUTO_JS_LIBRARIES is disabled.
// - AUTO_NATIVE_LIBRARIES is disabled.
// - AUTO_ARCHIVE_INDEXES is disabled.
// - DEFAULT_TO_CXX is disabled.
// - USE_GLFW is set to 0 rather than 2 by default.
// - ALLOW_UNIMPLEMENTED_SYSCALLS is disabled.
Expand All @@ -1168,13 +1167,6 @@ var STRICT = false;
// [link]
var IGNORE_MISSING_MAIN = true;

// Automatically attempt to add archive indexes at link time to archives that
// don't already have them. This can happen when GNU ar or GNU ranlib is used
// rather than ``llvm-ar`` or ``emar`` since the former don't understand the wasm
// object format.
// [link]
var AUTO_ARCHIVE_INDEXES = true;

// Add ``"use strict;"`` to generated JS
// [link]
var STRICT_JS = false;
Expand Down Expand Up @@ -2188,4 +2180,5 @@ var LEGACY_SETTINGS = [
['MIN_EDGE_VERSION', [0x7FFFFFFF], 'No longer supported'],
['MIN_IE_VERSION', [0x7FFFFFFF], 'No longer supported'],
['WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG', [0], 'No longer supported'],
['AUTO_ARCHIVE_INDEXES', [0, 1], 'No longer needed'],
];
16 changes: 0 additions & 16 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9121,22 +9121,6 @@ def test_response_file_bom(self):
create_file('test.rsp', b'\xef\xbb\xbf--version', binary=True)
self.run_process([EMCC, '@test.rsp'])

def test_archive_empty(self):
# This test added because we had an issue with the AUTO_ARCHIVE_INDEXES failing on empty
# archives (which inherently don't have indexes).
self.run_process([EMAR, 'crS', 'libfoo.a'])
self.run_process([EMCC, '-Werror', 'libfoo.a', test_file('hello_world.c')])

def test_archive_no_index(self):
create_file('foo.c', 'int foo = 1;')
self.run_process([EMCC, '-c', 'foo.c'])
self.run_process([EMCC, '-c', test_file('hello_world.c')])
# The `S` flag means don't add an archive index
self.run_process([EMAR, 'crS', 'libfoo.a', 'foo.o'])
# wasm-ld supports archive files without an index (unlike GNU ld) as of
# https://github.com/llvm/llvm-project/pull/78821
self.run_process([EMCC, 'libfoo.a', 'hello_world.o'])

def test_archive_non_objects(self):
create_file('file.txt', 'test file')
self.run_process([EMCC, '-c', test_file('hello_world.c')])
Expand Down
36 changes: 0 additions & 36 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,38 +201,6 @@ def embed_memfile(options):
not settings.GENERATE_SOURCE_MAP)))


def is_ar_file_with_missing_index(archive_file):
# We parse the archive header outselves because llvm-nm --print-armap is slower and less
# reliable.
# See: https://github.com/emscripten-core/emscripten/issues/10195
archive_header = b'!<arch>\n'
file_header_size = 60

with open(archive_file, 'rb') as f:
header = f.read(len(archive_header))
if header != archive_header:
# This is not even an ar file
return False
file_header = f.read(file_header_size)
if len(file_header) != file_header_size:
# We don't have any file entires at all so we don't consider the index missing
return False

name = file_header[:16].strip()
# If '/' is the name of the first file we have an index
return name != b'/'


def ensure_archive_index(archive_file):
# Fastcomp linking works without archive indexes.
if not settings.AUTO_ARCHIVE_INDEXES:
return
if is_ar_file_with_missing_index(archive_file):
diagnostics.warning('emcc', '%s: archive is missing an index; Use emar when creating libraries to ensure an index is created', archive_file)
diagnostics.warning('emcc', '%s: adding index', archive_file)
run_process([shared.LLVM_RANLIB, archive_file])


def generate_js_sym_info():
# Runs the js compiler to generate a list of all symbols available in the JS
# libraries. This must be done separately for each linker invokation since the
Expand Down Expand Up @@ -2696,10 +2664,6 @@ def process_libraries(state, linker_inputs):
settings.JS_LIBRARIES = [lib[1] for lib in settings.JS_LIBRARIES]
state.link_flags = new_flags

for _, f in linker_inputs:
if building.is_ar(f):
ensure_archive_index(f)


class ScriptSource:
def __init__(self):
Expand Down

0 comments on commit 88a3afc

Please sign in to comment.