156 Commits

Author SHA1 Message Date
Sam Clegg
70b76a172d [WebAssembly] Create section start symbols automatically for all sections
These symbols only get included in the output symbols table if
they are used in a relocation.

This behaviour matches more closely the ELF object writer.

Differential Revision: https://reviews.llvm.org/D46561

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332005 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 17:38:35 +00:00
Sam Clegg
0af44d6939 [WebAssembly] MC: Use existing MCSymbol.Index field rather than inventing extra mapping
MCSymbol has getIndex/setIndex which are implementation defined
and on other platforms are used to store the symbol table
index.  It makes sense to use this rather than invent a new
mapping.

Differential Revision: https://reviews.llvm.org/D46555

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331705 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-08 00:08:21 +00:00
Sam Clegg
b1872a2617 [WebAssembly] Ensure all .debug_XXX section has proper symbol names
Updated wasm section symbols names to match section name, and ensure all
referenced sections will have a symbol (per DWARF spec v3, Figure 43)

Patch by Yury Delendik!

Differential Revision: https://reviews.llvm.org/D46543

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331664 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-07 19:40:50 +00:00
Sam Clegg
1c4e4c492f [WebAssembly] MC: Create and use first class section symbols
Differential Revision: https://reviews.llvm.org/D46335

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331413 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-02 23:11:38 +00:00
Sam Clegg
81352e1cb7 Fix release build breakage
This function was added in rL331220 but wasn't
testing in release configurations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331320 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-02 00:10:28 +00:00
Florian Hahn
fb5fad4f7c [MC] Add llvm_unreachable to toString to fix compile time warning.
Without this change, GCC 7 raises the warning below:
        control reaches end of non-void function

Reviewers: sbc100, andreadb

Reviewed By: andreadb

Differential Revision: https://reviews.llvm.org/D46304


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331255 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-01 11:18:31 +00:00
Gabor Buella
b86d2aaf27 NFC, Avoid a warning in WasmObjectWriter
The warning was (introduced in r331220):

lib/MC/WasmObjectWriter.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331251 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-01 10:21:10 +00:00
Sam Clegg
8b887213a7 [WebAssembly] MC: Improve debug output
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331220 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-30 19:40:57 +00:00
Nico Weber
0f38c60baf IWYU for llvm-config.h in llvm, additions.
See r331124 for how I made a list of files missing the include.
I then ran this Python script:

    for f in open('filelist.txt'):
        f = f.strip()
        fl = open(f).readlines()

        found = False
        for i in xrange(len(fl)):
            p = '#include "llvm/'
            if not fl[i].startswith(p):
                continue
            if fl[i][len(p):] > 'Config':
                fl.insert(i, '#include "llvm/Config/llvm-config.h"\n')
                found = True
                break
        if not found:
            print 'not found', f
        else:
            open(f, 'w').write(''.join(fl))

and then looked through everything with `svn diff | diffstat -l | xargs -n 1000 gvim -p`
and tried to fix include ordering and whatnot.

No intended behavior change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331184 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-30 14:59:11 +00:00
Sam Clegg
bfeca0b120 [WebAssembly] Section symbols must have local binding
Summary: Also test for symbols information in test/MC/WebAssembly/debug-info.ll.

Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D46160

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331005 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-27 00:17:21 +00:00
Sam Clegg
db15975983 [WebAssembly] Write DWARF data into wasm object file
- Writes ".debug_XXX" into corresponding custom sections.
- Writes relocation records into "reloc.debug_XXX" sections.

Patch by Yury Delendik!

Differential Revision: https://reviews.llvm.org/D44184

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330982 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-26 19:27:28 +00:00
Sam Clegg
14598cb5be [WebAssembly] Add version to object file metadata
Summary: See https://github.com/WebAssembly/tool-conventions/issues/54

Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

Differential Revision: https://reviews.llvm.org/D46069

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330969 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-26 18:15:32 +00:00
Chandler Carruth
8801c5f87b [wasm] Fix uninitialized memory introduced in r330749.
Found with MSan. This was causing all the WASM MC tests to fail about
10% of the time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330764 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-24 20:30:56 +00:00
Sam Clegg
194a4e0c23 [WebAssembly] Use section index in relocation section header
Rather than referring to sections my their code, use the
absolute index of the target section within the module.

See https://github.com/WebAssembly/tool-conventions/issues/52

Differential Revision: https://reviews.llvm.org/D45980

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330749 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-24 18:11:36 +00:00
Sam Clegg
3f46946fed [WebAssembly] MC: Refactor section creation code
Remove the use of default argument in favor of a separate
startCustomSection method.

Differential Revision: https://reviews.llvm.org/D45794

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330632 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-23 19:16:19 +00:00
Sam Clegg
13c09234d6 [WebAssembly] Allow for the creation of user-defined custom sections
This patch adds a way for users to create their own custom sections to
be added to wasm files. At the LLVM IR layer, they are defined through
the "wasm.custom_sections" named metadata. The expected use case for
this is bindings generators such as wasm-bindgen.

Patch by Dan Gohman

Differential Revision: https://reviews.llvm.org/D45297

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329315 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-05 17:01:39 +00:00
Nicholas Wilson
44818a31b7 [WebAssembly] Disallow weak undefined globals in the object format
This implements https://github.com/WebAssembly/tool-conventions/pull/47

Differential Revision: https://reviews.llvm.org/D44201

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327146 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-09 16:30:44 +00:00
Nicholas Wilson
022e5fa26f [WebAssembly] Reorder reloc sections to come between symtab and name
This is required in order to enable relocs to be validated
as they are read in.

Also update tests with new section ordering.

Differential Revision: https://reviews.llvm.org/D43940

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326694 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-05 12:59:03 +00:00
Sam Clegg
9f474dee9e [WebAssembly] Use uint8_t for single byte values to match the spec
The original BinaryEncoding.md document used to specify that
these values were `varint7`, but the official spec lists them
explicitly as single byte values and not LEB.

A similar change for wabt is in flight:
 https://github.com/WebAssembly/wabt/pull/782

Differential Revision: https://reviews.llvm.org/D43921

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326454 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-01 18:06:21 +00:00
Nicholas Wilson
15d6598bc2 [WebAssembly] Reorder symbol table to match MC order
This removes a TODO introduced in rL325860

Differential Revision: https://reviews.llvm.org/D43685

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326334 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-28 17:19:48 +00:00
Sam Clegg
e14b24839c [WebAssembly] Remove DataSize from linking metadata section
Neither the linker nor the runtime need this information
anymore.  We were originally using this to model BSS size
but the plan is now to use the segment metadata to allow
for BSS segments.

Differential Revision: https://reviews.llvm.org/D41366

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326267 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-27 23:57:37 +00:00
Eric Christopher
66a6908779 Simplify a DEBUG statement to remove a set but not used variable in release builds.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325959 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-23 21:14:47 +00:00
Sam Clegg
d5784797c6 [WebAssembly] Add first claass symbol table to wasm objects
This is combination of two patches by Nicholas Wilson:
  1. https://reviews.llvm.org/D41954
  2. https://reviews.llvm.org/D42495

Along with a few local modifications:
- One change I made was to add the UNDEFINED bit to the binary format
  to avoid the extra byte used when writing data symbols.  Although this
  bit is redundant for other symbols types (i.e. undefined can be
  implied if a function or global is a wasm import)
- I prefer to be explicit and consistent and not have derived flags.
- Some field renaming.
- Some reverting of unrelated minor changes.
- No test output differences.

Differential Revision: https://reviews.llvm.org/D43147

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325860 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-23 05:08:34 +00:00
Sam Clegg
f010b43ca2 [WebAssembly] MC: Make explicit our current lack of support for relocations against unnamed temporary symbols.
Add an explicit check before looking up symbol in SymbolIndices.
This was previously silently succeeding and returning zero for such
unnamed temporaries.

Differential Revision: https://reviews.llvm.org/D43365

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325367 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-16 18:06:05 +00:00
Sam Clegg
ddc563a763 [WebAssembly] MC: Remove redundant struct types
Differential Revision: https://reviews.llvm.org/D43210

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324957 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-12 22:41:29 +00:00
Sam Clegg
bfa1dc6a7a [WebAssembly] MC: Remove unused code for handling of wasm globals
For now, we are not using wasm globals, except for modeling of
the stack points.

Alos, factor out common struct WasmGlobalType, which matches the
name for that tuple in the Wasm spec and rename methods
to "isBindingGlobal", "isTypeGlobal" to avoid ambiguity.

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D42750

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323901 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-31 19:50:14 +00:00
Sam Clegg
58528fe174 [WebAssembly] MC: Resolve aliases when creating provisional table entries
This change is useful for the upcoming addition of the symbol
table (D41954) since in that world aliases for given function
all share the same function index.

This change does not effect lld because it essentially ignores
the wasm "table".  The table exists only to the wasm objects
will validate and disassembly meaningfully.

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D42095

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323900 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-31 19:28:47 +00:00
Sam Clegg
6c3c15cc0f [WebAssembly] Remove some unused code and tidy logging. NFC.
Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D42540

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323846 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-31 04:21:44 +00:00
Sam Clegg
4fcde573ba [WebAssembly] Remove "name" section of object wasm object files
LLD is unaffected, no changes needed there. LLD continues to
write out a name section, using the symbol names.

Fixes: https://github.com/WebAssembly/tool-conventions/issues/37

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D42425

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323234 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-23 18:30:04 +00:00
Sam Clegg
5d85c66118 [WebAssembly] Store function index rather than table index in TABLE_INDEX relocations
Relocations of type R_WEBASSEMBLY_TABLE_INDEX represent places
where the table index for a given function is needed.  While the
value stored in this location is a table index, the index in
the relocation entry itself is a function index (the index of
the function which is to be called indirectly).

This is how is was spec'd originally but the LLVM implementation
didn't do this.  This makes things a little simpler in the linker
since the table in the input file can essentially be ignored that
the output table can be created purely based on these relocations.

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D42080

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323165 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-23 01:23:17 +00:00
Sam Clegg
3fb85bc80d [WebAssembly] MC: Start table at offset 1 rather than 0
Summary:
For consistency with the output of lld.

This is useful in runnable binaries as can them be sure the
null function pointer will never be a valid argument
call_indirect.

Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

Differential Revision: https://reviews.llvm.org/D42284

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322978 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-19 18:57:01 +00:00
Sam Clegg
eb7fd730fa [WebAssembly] Remove debug names from symbol table
Get rid of DEBUG_FUNCTION_NAME symbols. When we actually debug
data, maybe we'll want somewhere to put it... but having a symbol
that just stores the name of another symbol seems odd.
It means you have multiple Symbols with the same name, one
containing the actual function and another containing the name!

Store the names in a vector on the WasmObjectFile when reading
them in. Also stash them on the WasmFunctions themselves.
The names are //not// "symbol names" or aliases or anything,
they're just the name that a debugger should show against the
function body itself. NB. The WasmObjectFile stores them so that
they can be exported in the YAML losslessly, and hence the tests
can be precise.

Enforce that the CODE section has been read in before reading
the "names" section. Requires minor adjustment to some tests.

Patch by Nicholas Wilson!

Differential Revision: https://reviews.llvm.org/D42075

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322741 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-17 19:28:43 +00:00
Dan Gohman
e8afc14df4 [WebAssembly] Make WasmObjectWriter's destructor public; NFC
This fixes the FIXME introduced in r315327.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322490 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-15 17:06:23 +00:00
Sam Clegg
f2243a7f0e [WebAssembly] MC: Remove SetUsed argument when calling MCSymbol::isDefined et al
Summary:
This argument (the isUsed flag) seems to only be relevant
when parsing.  Other calls sites such as these don't seem
to ever use it.

Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish

Differential Revision: https://reviews.llvm.org/D41970

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322332 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-11 23:59:16 +00:00
Sam Clegg
2c77fcc6e1 [WebAssemlby] MC: Don't write COMDAT symbols as global imports
This was causing undefined references at link time in lld.

Differential Revision: https://reviews.llvm.org/D41959

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322309 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-11 20:35:17 +00:00
Sam Clegg
e92250ac8f [WebAssembly] Add COMDAT support
This adds COMDAT support to the Wasm object-file format.
Spec: https://github.com/WebAssembly/tool-conventions/pull/31

Corresponding LLD change:
https://bugs.llvm.org/show_bug.cgi?id=35533, and D40845

Patch by Nicholas Wilson

Differential Revision: https://reviews.llvm.org/D40844

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322135 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-09 23:43:14 +00:00
Rafael Espindola
5d5caec1a9 Use a MCExpr for the size of MCFillFragment.
This allows the size to be found during ralaxation. This fixes
pr35858.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322131 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-09 22:48:37 +00:00
Sam Clegg
dbc354264d [WebAssembly] MC: Use zero for provisional value of undefined symbols
This is more in line with what happens in the final
executable when symbols are undefined (i.e. weak
references).

Differential Revision: https://reviews.llvm.org/D41840

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322130 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-09 22:44:02 +00:00
Sam Clegg
824ec49c1a [WebAssembly] MC: Fix for address taken aliases
Previously, taking the address for an alias would result in:
 "Symbol not found in table index space"

Increase test coverage for weak aliases.

This code should be more efficient too as it avoids building
the `IsAddressTaken` set.

Differential Revision: https://reviews.llvm.org/D41510

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321384 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-22 20:31:39 +00:00
Sam Clegg
5b1a4e4b7f [WebAssembly] Fix local references to weak aliases
When weak aliases are used with in same translation
unit we need to be able to directly reference to alias
and not just the thing it is aliases.  We do this by
defining both a wasm import and a wasm export in this
case that result in a single Symbol.  This change is
a partial revert of rL314245.  A corresponding lld
change address the previous issues we had with this.

See: https://github.com/WebAssembly/tool-conventions/issues/34

Differential Revision: https://reviews.llvm.org/D41472

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321242 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-21 02:30:38 +00:00
Dan Gohman
d4598fc0c7 [WebAssembly] Remove an obsolete comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321127 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-20 00:10:28 +00:00
Sam Clegg
5334180cf2 [WebAssembly] Implement @llvm.global_ctors and @llvm.global_dtors
Summary:
- lowers @llvm.global_dtors by adding @llvm.global_ctors
  functions which register the destructors with `__cxa_atexit`.
- impements @llvm.global_ctors with wasm start functions and linker metadata

See [here](https://github.com/WebAssembly/tool-conventions/issues/25) for more background.

Subscribers: jfb, dschuff, mgorny, jgravelle-google, aheejin, sunfish

Differential Revision: https://reviews.llvm.org/D41211

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320774 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-15 00:17:10 +00:00
Michael Zolotukhin
ac904a2343 Remove redundant includes from lib/MC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320624 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-13 21:30:54 +00:00
Sam Clegg
9fb3467cfe Reland "[WebAssembly] Import the linear memory and function table."
Original change: https://reviews.llvm.org/D40875

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320432 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-11 23:03:38 +00:00
Sam Clegg
03f3a72f26 Revert "[WebAssembly] Import the linear memory and function table."
We need to a little time to prepare and lld-side change that
supports this.

Original change: https://reviews.llvm.org/D40875

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320003 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-07 03:05:45 +00:00
Dan Gohman
edc3af3e9a [WebAssembly] Import the linear memory and function table.
Instead of having .o files contain linear-memory and function table
definitions, use imports. This is more consistent with the stack pointer
being imported, and it's consistent with the linker being the one to
decide whether linear memory and function table are imported or defined
in the linked output. This implements tool-conventions #23.

Differential Revision: https://reviews.llvm.org/D40875


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319989 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06 23:57:11 +00:00
Dan Gohman
73135b400e [WebAssembly] Remove WASM_STACK_POINTER.
WASM_STACK_POINTER and the .stack_pointer directive are no longer needed
now that the stack pointer global is an import.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319956 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06 20:56:40 +00:00
Dan Gohman
ca99fdb493 [WebAssembly] Make stack-pointer imports mutable.
This is not currently valid by the wasm spec, however:
 - It replaces doing set_global on an immutable global, which is also
   not valid.
 - It's expected be valid in the near future:
   https://github.com/WebAssembly/threads/blob/master/proposals/threads/Globals.md
 - This only occurs before linking, so a fully linked object will be
   valid.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319810 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-05 18:29:48 +00:00
Dan Gohman
f07a1d491b [WebAssembly] Implement WASM_STACK_POINTER.
Use the .stack_pointer directive to implement WASM_STACK_POINTER for
specifying a global variable to be the stack pointer.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319797 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-05 17:23:43 +00:00
Sam Clegg
1f4bd62fa3 Reland "[WebAssembly] Add visibility flag to Wasm symbol flags""
Original change was rL319488.

This was reverted rL319602 due to a gcc 7.1 warning.

Differential Revision: https://reviews.llvm.org/D40772

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319626 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-03 01:19:23 +00:00