[PATCH] D42095: [WebAssembly] Symbol changes #3: Cosmetic table, LLVM. NFC.

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 14:10:39 PST 2018


ncw added a comment.

Thanks for the review!



================
Comment at: lib/MC/WasmObjectWriter.cpp:220
   DenseMap<const MCSymbolWasm *, uint32_t> SymbolIndices;
+  // Maps function symbol indices to the table element index space. Used
+  // for TABLE_INDEX relocation types (i.e. address taken functions).
----------------
sbc100 wrote:
> sbc100 wrote:
> > Maps function index to table element index, no?  Only functions can exist in this map right?
> Also, this isn't really map is it?  It more a list of function indexes to be written to the indirect function table.
> 
> With that in mind, why not call it TableElems, perhaps?
Functions and function imports too. It's a map in the sense that it's an int->int lookup table; it's just a dense map with bounded elements so an array made sense.

`TableIndices[i]` is the table index of the ith function, so the name makes sense to me.


================
Comment at: lib/MC/WasmObjectWriter.cpp:515
+    uint32_t SymbolIndex = SymbolIndices[Sym];
+    int32_t TableIndex = TableIndices[SymbolIndex];
+    assert(TableIndex >= 0);
----------------
sbc100 wrote:
> This doesn't look like it should work to me.
> 
> TableIndices is not a map.. but a list of function indexes.. so it seems like this will look up the N'th element in the table, not the table entry for function N.
It's an array more than a vector really.


================
Comment at: test/MC/WebAssembly/weak-alias.ll:197
+; CHECK-NEXT:           Value:           16
+; CHECK-NEXT:         Content:         '01000000'
+; CHECK-NEXT:   - Type:            CUSTOM
----------------
sbc100 wrote:
> How as this change generated a new data segment?  I guess maybe it was zero before so now it was elided?  
> 
> It looks to me like we really want to two different function addresses here for the address of the function itself and the address of the weak alias.  Its not until link time that these two things become the same thing.  Maybe it doesn't really matter as long as the linker can distinguish them, but it makes sense to be that there would be two different function addresses in this object file.
Ah, the test data before was skipping the section - see the "CHECK" in the original file, rather than "CHECK-NEXT". I thought it was useful to expand the test to assert on the section that was being skipped; it was odd that previously it was deliberately not examining the final segment.

"It's not until link time that they become the same thing" -> but the table in the object file is linked. The "provisional" values that are used for relocations in the object file are a preview of the values that would get written out. I think it makes sense to use the same rules for writing out provisional values as we do for writing out the actual values in LLD. Hence we don't put the exact same function twice in the table - there's really no point. Seeing a function appear multiple times in the table doesn't make the output any easier to read.


Repository:
  rL LLVM

https://reviews.llvm.org/D42095





More information about the llvm-commits mailing list