diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-05-06 15:19:55 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-05-06 15:19:55 -0700 |
commit | a3b3a516bd8117cd83aa0625839e614110d1fc0b (patch) | |
tree | 077d3bbbdf337e91de884c19ec3564440e616470 | |
parent | 5f2b05fd3d03e353e5f461a6d334e2c8e2eadd3a (diff) | |
download | binaryen-a3b3a516bd8117cd83aa0625839e614110d1fc0b.tar.gz binaryen-a3b3a516bd8117cd83aa0625839e614110d1fc0b.tar.bz2 binaryen-a3b3a516bd8117cd83aa0625839e614110d1fc0b.zip |
Use rpath instead of LD_LIBRARY_PATH for shared object use (#448)
Use the -rpath linker flag to locate libbinaryen-c.so instead of
injecting paths into the user's LD_LIBRARY_PATH
Also Link libsupport and libasmjs into libbinaryen-c
Fixes #444
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rwxr-xr-x | auto_update_tests.py | 22 | ||||
-rwxr-xr-x | check.py | 21 |
3 files changed, 23 insertions, 22 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e88767166..126bf3a6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,7 @@ ELSE() ADD_COMPILE_FLAG("-Wextra") ADD_COMPILE_FLAG("-Wno-unused-parameter") ADD_COMPILE_FLAG("-fno-omit-frame-pointer") + ADD_COMPILE_FLAG("-fPIC") IF(CMAKE_THREAD_LIBS_INIT) ADD_LINK_FLAG("${CMAKE_THREAD_LIBS_INIT}") ENDIF() @@ -116,6 +117,7 @@ SET(binaryen_c_SOURCES src/wasm.cpp ) ADD_LIBRARY(binaryen-c SHARED ${binaryen_c_SOURCES}) +TARGET_LINK_LIBRARIES(binaryen-c asmjs support) SET(binaryen-shell_SOURCES src/binaryen-shell.cpp diff --git a/auto_update_tests.py b/auto_update_tests.py index 8dac39faf..5380fc737 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -2,12 +2,6 @@ import os, sys, subprocess, difflib -# find our dynamic libraries -if os.environ.get('LD_LIBRARY_PATH'): - os.environ['LD_LIBRARY_PATH'] += os.pathsep + 'lib' -else: - os.environ['LD_LIBRARY_PATH'] = 'lib' - print '[ processing and updating testcases... ]\n' for asm in sorted(os.listdir('test')): @@ -102,7 +96,8 @@ for wast in sorted(os.listdir('test')): print '\n[ checking example testcases... ]\n' for t in sorted(os.listdir(os.path.join('test', 'example'))): - cmd = ['-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread'] + output_file = os.path.join('bin', 'example') + cmd = ['-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread', '-o', output_file] if t.endswith('.cpp'): cmd = [os.path.join('test', 'example', t), os.path.join('src', 'pass.cpp'), @@ -115,7 +110,8 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): '-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread'] print ' '.join(extra) subprocess.check_call(extra) - cmd = ['example.o', '-lbinaryen-c'] + cmd + # Link against the binaryen C library DSO, using an executable-relative rpath + cmd = ['example.o', '-lbinaryen-c'] + cmd + ['-Wl,-rpath=$ORIGIN/../lib'] else: continue if os.environ.get('COMPILER_FLAGS'): @@ -123,8 +119,12 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): cmd.append(f) cmd = [os.environ.get('CXX') or 'g++', '-std=c++11'] + cmd print ' '.join(cmd) - subprocess.check_call(cmd) - actual = subprocess.Popen(['./a.out'], stdout=subprocess.PIPE).communicate()[0] - open(os.path.join('test', 'example', '.'.join(t.split('.')[:-1]) + '.txt'), 'w').write(actual) + try: + subprocess.check_call(cmd) + actual = subprocess.Popen([output_file], stdout=subprocess.PIPE).communicate()[0] + open(os.path.join('test', 'example', '.'.join(t.split('.')[:-1]) + '.txt'), 'w').write(actual) + finally: + os.remove(output_file) + print '\n[ success! ]' @@ -50,12 +50,6 @@ BIN_DIR = os.path.abspath(os.path.join(WATERFALL_BUILD_DIR, 'wasm-install', 'bin os.environ['BINARYEN'] = os.getcwd() -# find our dynamic libraries -if os.environ.get('LD_LIBRARY_PATH'): - os.environ['LD_LIBRARY_PATH'] += os.pathsep + 'lib' -else: - os.environ['LD_LIBRARY_PATH'] = 'lib' - def fetch_waterfall(): rev = open(os.path.join('test', 'revision')).read().strip() try: @@ -601,7 +595,8 @@ if has_vanilla_emcc and has_vanilla_llvm: print '\n[ checking example testcases... ]\n' for t in sorted(os.listdir(os.path.join('test', 'example'))): - cmd = ['-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread'] + output_file = os.path.join('bin', 'example') + cmd = ['-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread', '-o', output_file] if t.endswith('.cpp'): cmd = [os.path.join('test', 'example', t), os.path.join('src', 'pass.cpp'), @@ -614,7 +609,8 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): '-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread'] print ' '.join(extra) subprocess.check_call(extra) - cmd = ['example.o', '-lbinaryen-c'] + cmd + # Link against the binaryen C library DSO, using an executable-relative rpath + cmd = ['example.o', '-lbinaryen-c'] + cmd + ['-Wl,-rpath=$ORIGIN/../lib'] else: continue if os.environ.get('COMPILER_FLAGS'): @@ -622,9 +618,12 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): cmd.append(f) cmd = [os.environ.get('CXX') or 'g++', '-std=c++11'] + cmd print ' '.join(cmd) - subprocess.check_call(cmd) - actual = subprocess.Popen(['./a.out'], stdout=subprocess.PIPE).communicate()[0] - expected = open(os.path.join('test', 'example', '.'.join(t.split('.')[:-1]) + '.txt')).read() + try: + subprocess.check_call(cmd) + actual = subprocess.Popen([output_file], stdout=subprocess.PIPE).communicate()[0] + expected = open(os.path.join('test', 'example', '.'.join(t.split('.')[:-1]) + '.txt')).read() + finally: + os.remove(output_file) if actual != expected: fail(actual, expected) |