Skip to content

Fix linking SIDE_MODULE with ports#26514

Open
ryanking13 wants to merge 4 commits intoemscripten-core:mainfrom
ryanking13:side-module-pic
Open

Fix linking SIDE_MODULE with ports#26514
ryanking13 wants to merge 4 commits intoemscripten-core:mainfrom
ryanking13:side-module-pic

Conversation

@ryanking13
Copy link
Contributor

With the removal of the RELOCATABLE flag (cfb4642), building side module with ports are not working correctly because of 1) -fPIC flag missing when building ports, and 2) pic directory not correctly passed when calculating the libdir.

Without this, building a side module that links to the port library fails with the following error:

// dummy.c
#include <emscripten/emscripten.h>
#include <jpeglib.h>

EMSCRIPTEN_KEEPALIVE
int dummy_libjpeg_smoke_test(void) {
	struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;

	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&cinfo);
	jpeg_destroy_decompress(&cinfo);

	return 0;
}
$ emcc dummy.c -o dummy.wasm -s USE_LIBJPEG=1 -s SIDE_MODULE=1 -ljpeg

wasm-ld: error: /home/siha/dev/temp/emscripten-regression/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libjpeg.a(jdinput.c.o): relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `finish_input_pass`; recompile with -fPIC
wasm-ld: error: /home/siha/dev/temp/emscripten-regression/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libjpeg.a(jdinput.c.o): relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `start_input_pass`; recompile with -fPIC
wasm-ld: error: /home/siha/dev/temp/emscripten-regression/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libjpeg.a(jdinput.c.o): relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `reset_input_controller`; recompile with -fPIC
wasm-ld: error: /home/siha/dev/temp/emscripten-regression/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libjpeg.a(jdinput.c.o): relocation R_WASM_TABLE_INDEX_SLEB cannot be used against symbol `consume_markers`; recompile with -fPIC

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! I actually didn't know that this was some that ever worked.

@requires_network
def test_side_module_with_ports(self):
# Verify that ports can be used in side modules
self.emcc(test_file('jpeg_test.c'), args=['-sUSE_LIBJPEG', '-sSIDE_MODULE', '-ljpeg'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this into a full test that then uses the resulting side module from a main module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. How does it look now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants