aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-08-18 22:05:23 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-08-18 22:05:23 -0700
commit1f666759fe6170a7be2399e794a4adfa32a82b1e (patch)
tree0aee360758d23229606977e7033bc65a65aa94db
parent7618310d969295b610805b7240048e7e2a737f36 (diff)
warn on -I and -L to absolute paths, which may be to local system headers/libraries that are not portable
-rwxr-xr-xemcc2
-rwxr-xr-xtests/runner.py13
2 files changed, 15 insertions, 0 deletions
diff --git a/emcc b/emcc
index e78b1416..4df5c39e 100755
--- a/emcc
+++ b/emcc
@@ -516,6 +516,8 @@ try:
elif newargs[i] == '--remove-duplicates':
remove_duplicates = True
newargs[i] = ''
+ elif newargs[i].startswith(('-I/', '-L/')):
+ print >> sys.stderr, 'emcc: warning: -I or -L of an absolute path encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)' # Of course an absolute path to a non-system-specific library or header is fine, and you can ignore this warning. The danger are system headers that are e.g. x86 specific and nonportable. The emscripten bundled headers are modified to be portable, local system ones are generally not
newargs = [ arg for arg in newargs if arg is not '' ]
if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level]
diff --git a/tests/runner.py b/tests/runner.py
index b80509ff..0a37db54 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -6968,6 +6968,19 @@ f.close()
self.assertContained('hello from lib', run_js(os.path.join(self.get_dir(), 'a.out.js')))
assert not os.path.exists('a.out') and not os.path.exists('a.exe'), 'Must not leave unneeded linker stubs'
+ def test_abspaths(self):
+ # Includes with absolute paths are generally dangerous, things like -I/usr/.. will get to system local headers, not our portable ones.
+
+ shutil.copyfile(path_from_root('tests', 'hello_world.c'), 'main.c')
+
+ for args, expected in [(['-I/usr/something'], True),
+ (['-L/usr/something'], True),
+ (['-Isubdir/something'], False),
+ (['-Lsubdir/something'], False),
+ ([], False)]:
+ err = Popen(['python', EMCC, 'main.c'] + args, stderr=PIPE).communicate()[1]
+ assert ('emcc: warning: -I or -L of an absolute path encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)' in err) == expected, err
+
def test_local_link(self):
# Linking a local library directly, like /usr/lib/libsomething.so, cannot work of course since it
# doesn't contain bitcode. However, when we see that we should look for a bitcode file for that