[PATCH] D91870: [WebAssembly] Add support for table linking to wasm-ld

Andy Wingo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 05:23:59 PST 2020


wingo added inline comments.


================
Comment at: lld/wasm/SyntheticSections.h:156
-    //     a validation error to include a call_indirect instruction if there
-    //     is not table.
-    return !config->importTable;
----------------
wingo wrote:
> sbc100 wrote:
> > How is (2) handled after this change?
> > 
> > Imagine a program that contains just this code:
> > 
> > ```
> > EXPORT_OR_OTHERWISE_KEEP_ALIVE
> >  void call_func(func_ptr f) {
> >     f()
> > }
> > ```
> > 
> > Now we a call_indirect instruction but no TABLE_INDEX relocations.
> > 
> > In fact we have no relocations at all, but the resulting program needs to have a table in order to validate.
> > 
> > I guess once you move to new relocation model to call_indirect this program *will* have a TABLE_NUMBER relocation.    But we need to support the case where this code was compiled with the old model too.
> > 
> > The change to lld/test/wasm/stack-pointer.ll looks a little suspicious because it removes the table from the object file which would potentially make it fail to validate.
> Humm this is a head-scratcher!  I think https://reviews.llvm.org/D91637 may have introduced a bad state.
> 
> Backing up -- The intention with the change here is that any object file that needs an indirect function table should either
>  - have a `TABLE_NUMBER` reloc against the table ("new" object file with `call_indirect`)
>  - have the table marked as no-strip ("new" object file, caused by assembler recording a `TABLE_INDEX` reloc)
>  - or, if the incoming object file is "old" (has table import or definition but no table symbols), then those tables are treated as having no-strip symbols.
> 
> For new files, this works fine.  For very old files, also fine -- they always have an __indirect_function_table import.  But since https://reviews.llvm.org/D91637, there can be object files which refer to `__indirect_function_table `via `call_indirect`, but which don't have `TABLE_INDEX` relocs.  In that case the object file will lack the `__indirect_function_table` import.
> 
> The problem is mitigated in that if any other linker input imports `__indirect_function_table`, then the result is an output file that validates.
Fixed via https://reviews.llvm.org/D92840.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91870/new/

https://reviews.llvm.org/D91870



More information about the llvm-commits mailing list