Skip to content

Use -lxxx internally rather than full library path #14342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2021
Merged

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 2, 2021

Since we already supply the correct -L path we can rely on wasm-ld to
find, for example, libc.a by simply passing -lc rather than its full
path.

This is in line with what gcc and clang do.

This is almost NFC, except in that case where the user supplies a
library path via -L which happens to contain a system library
(e.g. libc.a). In this case, as with clang or gcc, that file will be
chosen over the system one.

This makes the linker command lines shorter, more readable, more inline
with other compilers.

@sbc100 sbc100 requested review from kripken and dschuff June 2, 2021 01:31
@sbc100 sbc100 force-pushed the wasm_ld_lib_resolve branch from 3a7c7b6 to aac5d8c Compare June 2, 2021 18:00
emcc.py Outdated
@@ -462,7 +462,7 @@ def is_supported(f):
# lld allows various flags to have either a single -foo or double --foo
if f.startswith(flag) or f.startswith('-' + flag):
diagnostics.warning('linkflags', 'ignoring unsupported linker flag: `%s`', f)
return False, takes_arg
return False, takes_arg and '=' not in f
Copy link
Member

Choose a reason for hiding this comment

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

I don't follow this. Perhaps a comment about why = is special?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@sbc100 sbc100 force-pushed the wasm_ld_lib_resolve branch 5 times, most recently from a7d01cd to 1581b6e Compare June 2, 2021 20:55
emcc.py Outdated
Comment on lines 465 to 467
# Skip the next argument if this linker flag takes and argument and that
# argument was not specified as a separately (i.e. it was specified as
# single arg containing an `=` char.)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Skip the next argument if this linker flag takes and argument and that
# argument was not specified as a separately (i.e. it was specified as
# single arg containing an `=` char.)
# Skip the next argument if this linker flag takes an argument and that
# argument was not specified separately (i.e. it was specified as
# single arg containing an `=` char.)

Is that right?

If so then this makes sense to me. But then isn't this a separate fix from the PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yes, this is a bug fix, but it also happens to be needed as part of this change. I split it out as #14356.

The reason this change depends on it is that other wise test_supported_linker_flags will start failing. The reason this change depends on that fix goes like this:

  1. We specify the -L/path/to/sysroot as the first system link flag returned by emsdk_ldflags
  2. System link flags get added to user link flags
  3. If, as in that test, that last user link flag is an ignored one of the form -Wl,-rpath=foo then the next argument will be ignored.. which will be the -L/path/to/sysroot
  4. This will cause -lc to not be found, but that didn't matter previously because we were using full paths the libc.a prior to this change.

@sbc100 sbc100 force-pushed the wasm_ld_lib_resolve branch 2 times, most recently from 8cdcef8 to aa6e451 Compare June 3, 2021 03:14
Since we already supply the correct `-L` path we can rely on wasm-ld to
find, for example, libc.a by simply pasing `-lc` rather than its full
path.

This is in line with what gcc and clang do.

This is almost NFC, except in that case where the user supplies and
library path via `-L` which happens to contains a file called `libc.a`.
In this case, as with clang or gcc, that file will be chosen over the
system one.

This makes the linker command lines shorter, more readable, more inline
with other compilers.
@sbc100 sbc100 force-pushed the wasm_ld_lib_resolve branch from aa6e451 to fd0f829 Compare June 3, 2021 17:05
@sbc100 sbc100 enabled auto-merge (squash) June 3, 2021 17:06
@sbc100 sbc100 merged commit 1ccae3e into main Jun 3, 2021
@sbc100 sbc100 deleted the wasm_ld_lib_resolve branch June 3, 2021 19:37
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.

3 participants