This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Add support for -Bsymbolic
ClosedPublic

Authored by sbc100 on Oct 9 2020, 11:06 AM.

Details

Summary

This flag works in a similar way to the ELF linker in that it
will resolve any defined symbols to their local definition with
a shared library.

This is also the default behavior for or -pie executables.

Diff Detail

Event Timeline

sbc100 created this revision.Oct 9 2020, 11:06 AM
Herald added a project: Restricted Project. · View Herald Transcript
sbc100 requested review of this revision.Oct 9 2020, 11:06 AM
sbc100 edited reviewers, added: azakai, dschuff; removed: jhenderson.Oct 9 2020, 11:11 AM
sbc100 updated this revision to Diff 297285.Oct 9 2020, 11:14 AM

comments

sbc100 updated this revision to Diff 297287.Oct 9 2020, 11:19 AM

comments

This change will allows us to remove the corresponding binaryen code: https://github.com/WebAssembly/binaryen/pull/3211 and instead pass -Bsymbolic when linking MAIN_MODULE's in emscripten.

Harbormaster completed remote builds in B74623: Diff 297287.
MaskRay added inline comments.Oct 9 2020, 11:41 AM
lld/wasm/Driver.cpp
496

In ELF, -Bsymbolic is redundant for executables (-no-pie or -pie).

sbc100 added inline comments.Oct 9 2020, 11:49 AM
lld/wasm/Driver.cpp
496

Interesting, so you are saying the -Bsymbolic is basically the default for executable?

Wouldn't that mean that, for example, LD_PRELOAD would not work for symbols in the main executable? My understanding is that -Bsymbolic would prevent LD_PRELOAD from overriding symbols because they would be bound locally. Although I guess I am wrong?

sbc100 added inline comments.Oct 9 2020, 11:56 AM
lld/wasm/Driver.cpp
496

Indeed you are right, it looks like LD_PRELOAD as no effect on the main executable itself. TIL!

sbc100 updated this revision to Diff 297308.Oct 9 2020, 12:30 PM

feedback

sbc100 edited the summary of this revision. (Show Details)Oct 9 2020, 12:48 PM
sbc100 updated this revision to Diff 297331.Oct 9 2020, 1:51 PM
sbc100 edited the summary of this revision. (Show Details)

revert

MaskRay added inline comments.Oct 9 2020, 2:49 PM
lld/wasm/Driver.cpp
496

-Bsymbolic is basically the default for executable.
The symbol resolution order: exe, preloaded, needed

In preloaded, the LD_PRELOADed library is listed in a breadth-first search order.
needed is similar.

sbc100 edited reviewers, ... removed: jhenderson.

(I've got a herald rule to auto-add myself to reviews touching llvm-readobj amongst other tools - no point trying to work around it!)

llvm/tools/llvm-readobj/WasmDumper.cpp
186–189 ↗(On Diff #297331)

Shouldn't this bit have some dedicated llvm-readobj testing?

sbc100 edited reviewers, ... removed: jhenderson.

(I've got a herald rule to auto-add myself to reviews touching llvm-readobj amongst other tools - no point trying to work around it!)

Sorry, didn't mean to try to work around your herald stuff, I also use herald to be notified about WebAssembly related thing. I think I was just trying to be precise about who I thought would be good reviewer. I won't remove your name anymore from that field.

In general, would it would make sense to add yourself to subscriber rather than reviewer if you want to monitor all changes in these areas? You could then add yourself as a reviewer to change that you care about? Or do you want to actually be a reviewer all of all change to lld? For example, this specific change, do you want to be a reviewer?

sbc100 added inline comments.Oct 12 2020, 6:56 AM
llvm/tools/llvm-readobj/WasmDumper.cpp
186–189 ↗(On Diff #297331)

Yes, actually I think I will revert this part since I'm not actually using readobj in the testing anymore.

I will land this separately with its own test.

sbc100 edited reviewers, ... removed: jhenderson.

(I've got a herald rule to auto-add myself to reviews touching llvm-readobj amongst other tools - no point trying to work around it!)

Sorry, didn't mean to try to work around your herald stuff, I also use herald to be notified about WebAssembly related thing. I think I was just trying to be precise about who I thought would be good reviewer. I won't remove your name anymore from that field.

In general, would it would make sense to add yourself to subscriber rather than reviewer if you want to monitor all changes in these areas? You could then add yourself as a reviewer to change that you care about? Or do you want to actually be a reviewer all of all change to lld? For example, this specific change, do you want to be a reviewer?

Sorry, I see now that it was probably the fact that I touched objdump here that added you as a reviewer. My comment is less relevant in that case I guess.

sbc100 edited reviewers, ... removed: jhenderson.

(I've got a herald rule to auto-add myself to reviews touching llvm-readobj amongst other tools - no point trying to work around it!)

Sorry, didn't mean to try to work around your herald stuff, I also use herald to be notified about WebAssembly related thing. I think I was just trying to be precise about who I thought would be good reviewer. I won't remove your name anymore from that field.

In general, would it would make sense to add yourself to subscriber rather than reviewer if you want to monitor all changes in these areas? You could then add yourself as a reviewer to change that you care about? Or do you want to actually be a reviewer all of all change to lld? For example, this specific change, do you want to be a reviewer?

Sorry, I see now that it was probably the fact that I touched objdump here that added you as a reviewer. My comment is less relevant in that case I guess.

No problem! I'm keen to keep an eye on patches in the LLVM binutils (readelf, objdump etc), mostly for ELF, but I often chip in on other platforms too, in an effort to maintain consistency, make sure documentation is sorted etc. I'm not bothered by LLD (and don't have a herald rule setup for that), though I do sometimes help out with reviews in the ELF part of LLD too.

sbc100 updated this revision to Diff 297582.Oct 12 2020, 7:34 AM

Revert readobj part

sbc100 updated this revision to Diff 297723.Oct 12 2020, 4:56 PM

bsymbol is the default baviour for executables

kripken accepted this revision.Oct 12 2020, 5:08 PM
kripken added a subscriber: kripken.

I'm not an expert on the LLVM details here, but, the logic looks correct and that it properly corresponds to the original idea of this optimization (that this will replace).

This revision is now accepted and ready to land.Oct 12 2020, 5:08 PM
MaskRay added inline comments.Oct 12 2020, 5:10 PM
lld/wasm/Driver.cpp
496

I was wrong about the symbol resolution order.

In musl, LD_PRELOAD libraries are prepended to the DT_NEEDED list. The resolution order is a breadth-first search order starting from the executable, i.e. the order may be:
exe, preload0, preload1, needed0, needed1, needd0_of_preload0, needed1_of_preload0, needd0_of_needed0, ...

sbc100 added inline comments.Oct 12 2020, 5:15 PM
lld/wasm/Driver.cpp
496

Thanks for the update. The only thing that this change does now is to bind symbols in the executable (and -Bsymbolic libraries) to local definition (if they exist).

We have no concept of LD_PRELOAD yet in the WebAssembly (or emscripten) world.

Any objections to landing this change?

MaskRay accepted this revision.Oct 12 2020, 5:19 PM
MaskRay added inline comments.
lld/wasm/Driver.cpp
496

No objection (just wanted to mention that in ELF linkers, they don't warn about this combo).

The nice thing with the ELF behavior is that: if a project deliberately uses -Bsymbolic, it does not need to differentiate executable linker options from shared object linker options.

I know really little about wasm, though.

sbc100 added inline comments.Oct 12 2020, 5:23 PM
lld/wasm/Driver.cpp
496

I think eventually we will most likely do the same, but starting off more restrictive is probably safer.. we can always relax later, but tightening up restrictions is hard (because it can break people, as I'm sure you understand).

Our PIC ABI and shared library loading ABI still experimental so we actually don't want to encourage the use of this (or -pie or -shared) right now.

This revision was landed with ongoing or failed builds.Oct 12 2020, 5:25 PM
This revision was automatically updated to reflect the committed changes.