[llvm] r257416 - [WebAssembly] Define WebAssembly-specific relocation codes.

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 16:14:53 PST 2016


On Tue, Jan 19, 2016 at 3:58 PM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> On 19 January 2016 at 16:33, Dan Gohman <sunfish at mozilla.com> wrote:
> > WebAssembly functions are not loaded into the application address space.
> > Functions are identified, both statically, and in dynamic function
> pointer
> > values, through special index values (ignoring certain optimizations).
> >
> > Many ELF tools have relocation infrastructure that is very focused on
> > resolving a relocation by supplying a virtual address, or some function
> of
> > the virtual address. For example, in lld, the relocateOne hook isn't told
> > what symbol it's relocating or what its type is; it just gets passed the
> > resolved virtual address for the symbol. It is also told the relocation
> > code, so by using R_WEBASSEMBLY_FUNCTION, which comes from
> > VK_WebAssembly_FUNCTION, we can at least inform it that it needs to do
> > something different.
> >
> > Of course, it's also presumably possible to modify lld and other tools to
> > keep track of symbols in more places, and use their types to decide what
> to
> > do. I decided against this because it is also nice to have each
> relocation
> > code be used for a specific kind of value -- R_WEBASSEMBLY_DATA for
> virtual
> > addresses, and R_WEBASSEMBLY_FUNCTION for function indices. In theory, a
> > smart linker that knows the symbol types could even check that functions
> > always use R_WEBASSEMBLY_FUNCTION, for example.
> >
> > Another consideration is that not all ELF producers set .type for all
> > symbols. One can argue about whether this is a bug in those producers or
> > not, but using a relocation code seemed like it might be a little more
> > robust.
> >
> > All that said, I'm definitely open to feedback here.
>
> Sounds reasonable given the explanation. If the two relocations write
> different values they should be two relocations. How are data
> relocations represented BTW? So far the psabi is
>
> * R_WEBASSEMBLY_FUNCTION: Write the the index value of the function.
> * R_WEBASSEMBLY_DATA: ?
>

R_WEBASSEMBLY_DATA is just the virtual address of the symbol. It's just
like R_MIPS_32/R_MIPS_64 or similar relocations on lots of other targets.
Right now it decides whether to do a 32-bit or 64-bit relocation based on
the target architecture rather than using separate relocation codes as
other targets do, but I'd be open to changing it to R_WEBASSEMBLY_32 and
R_WEBASSEMBLY_64 if it's better to be consistent.


>
> Do you guys use Rel or Rela? Do addends even make sense?
>

Addends do make sense for data symbols, which have normal virtual
addresses. They use Rel at the moment, because the current relocation set
can go either way so we might as well save space, but that could change if
a need for Rela arises.

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160119/2b3f13b5/attachment.html>


More information about the llvm-commits mailing list