aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/WasmObjectFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
2018-04-24[WebAssembly] Use section index in relocation section headerSam Clegg1-29/+6
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 llvm-svn: 330749
2018-04-20[WebAssembly] Distinguish debug/symbol names in the Wasm structs. NFCNicholas Wilson1-15/+6
Differential Revision: https://reviews.llvm.org/D45021 llvm-svn: 330448
2018-04-12[WebAssembly] libObject: Don't include the name the size of custom sectionsSam Clegg1-1/+5
Differential Revision: https://reviews.llvm.org/D45579 llvm-svn: 329947
2018-03-14[WebAssembly] Identify COMDATs by index rather than string. NFCNicholas Wilson1-6/+11
This will enable an optimisation in LLD. Differential Revision: https://reviews.llvm.org/D44343 llvm-svn: 327522
2018-03-09[WebAssembly] Disallow weak undefined globals in the object formatNicholas Wilson1-0/+5
This implements https://github.com/WebAssembly/tool-conventions/pull/47 Differential Revision: https://reviews.llvm.org/D44201 llvm-svn: 327146
2018-03-06[WebAssebmly] Remove reloc ordering constraintSam Clegg1-3/+1
The MC layer doesn't currently emit relocations in offset order for the entire code section so this check was causing failures on the wasm waterfall. Perhaps we can re-instate this check if we divide the relocations per-function, or add extra ordering the MC object writer. Differential Revision: https://reviews.llvm.org/D44136 llvm-svn: 326765
2018-03-05[WebAssembly] Add validation to reloc sectionNicholas Wilson1-4/+40
We now check relocations offsets are within range, and the relocation index is valid. Also updated tests which contained invalid Wasm files that were previously not checked. Differential Revision: https://reviews.llvm.org/D43684 llvm-svn: 326697
2018-03-05[WebAssembly] Attach a name to globals similarly to function namingNicholas Wilson1-2/+8
This allows LLD to print the name for an InputGlobal when encountering an error. Differential Revision: https://reviews.llvm.org/D44033 llvm-svn: 326691
2018-03-02[WebAssembly] Check function type indexesNicholas Wilson1-1/+6
Also update tests containing invalid Wasm files, exposed by the check Differential Revision: https://reviews.llvm.org/D43954 llvm-svn: 326577
2018-03-01[WebAssembly] Use uint8_t for single byte values to match the specSam Clegg1-23/+11
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 llvm-svn: 326454
2018-02-28[WebAssembly] Fix copy-paste error in debugging stringNicholas Wilson1-1/+1
llvm-svn: 326326
2018-02-27[WebAssembly] Remove DataSize from linking metadata sectionSam Clegg1-5/+0
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 llvm-svn: 326267
2018-02-23[WebAssembly] Add first claass symbol table to wasm objectsSam Clegg1-135/+169
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 llvm-svn: 325860
2018-02-09[WebAssebmly] Report undefined symbols correctly in objdumpSam Clegg1-8/+13
Peviously we were reporting undefined symbol as being defined by the IMPORT sections. This change reports undefined symbols in the same that other formats do, and also removes the need to store the section with each symbol (since it can be derived from the symbol type). Differential Revision: https://reviews.llvm.org/D43101 llvm-svn: 324770
2018-01-31[WebAssembly] MC: Remove unused code for handling of wasm globalsSam Clegg1-4/+4
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 llvm-svn: 323901
2018-01-24[WebAssembly] Add minor helper functions to WasmObjectFileSam Clegg1-9/+18
Also, fix crash when exporting an imported function. Differential Revision: https://reviews.llvm.org/D42454 llvm-svn: 323290
2018-01-17[WebAssembly] Remove debug names from symbol tableSam Clegg1-10/+25
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 llvm-svn: 322741
2018-01-12[WebAssembly] Don't allow functions to be named twiceSam Clegg1-1/+6
The spec doesn't allow this. Differential Revision: https://reviews.llvm.org/D41974 llvm-svn: 322343
2018-01-09[WebAssembly] Add COMDAT supportSam Clegg1-0/+54
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 llvm-svn: 322135
2018-01-09[WebAssembly] Explicitly specify function/global index space in YAMLSam Clegg1-1/+3
These indexes are useful because they are not always zero based and functions and globals are referenced elsewhere by their index. This matches what we already do for the type index space. Differential Revision: https://reviews.llvm.org/D41877 llvm-svn: 322121
2017-12-21[WebAssembly] Remove unneeded sub-directorySam Clegg1-1/+1
This is the only wasm def (and likely likely will be for the foreseeable) file so no need for a sub-directory Differential Revision: https://reviews.llvm.org/D41476 llvm-svn: 321246
2017-12-21[WebAssembly] Fix local references to weak aliasesSam Clegg1-9/+18
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 llvm-svn: 321242
2017-12-17[WebAssembly] Export some more info on wasm funtionsSam Clegg1-4/+7
Summary: These fields are useful for lld's gc-sections support Also remove an unused field. Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish Differential Revision: https://reviews.llvm.org/D41320 llvm-svn: 320946
2017-12-14Fix many -Wsign-compare and -Wtautological-constant-compare warnings.Zachary Turner1-1/+1
Most of the -Wsign-compare warnings are due to the fact that enums are signed by default in the MS ABI, while the tautological comparison warnings trigger on x86 builds where sizeof(size_t) is 4 bytes, so N > numeric_limits<unsigned>::max() is always false. Differential Revision: https://reviews.llvm.org/D41256 llvm-svn: 320750
2017-12-14[WebAssembly] Add support for init functions linking metadataSam Clegg1-1/+20
Summary: This change lays the groundwork lowering of @llvm.global_ctors and @llvm.global_dtors for the wasm object format. Some parts of this patch are subset of: https://reviews.llvm.org/D40759 See https://github.com/WebAssembly/tool-conventions/issues/25 Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish Differential Revision: https://reviews.llvm.org/D41208 llvm-svn: 320742
2017-12-06[WebAssembly] Commit a file I accidentally omitted from r319956.Dan Gohman1-1/+0
llvm-svn: 319962
2017-12-03Reland "[WebAssembly] Add visibility flag to Wasm symbol flags""Sam Clegg1-1/+3
Original change was rL319488. This was reverted rL319602 due to a gcc 7.1 warning. Differential Revision: https://reviews.llvm.org/D40772 llvm-svn: 319626
2017-12-02[WebAssembly] Revert r319488 "Add visibility flag to Wasm symbol flags"Heejin Ahn1-3/+1
This patch reportedly broke one of LLVM bots (ubuntu-gcc7.1-werror). See http://lab.llvm.org:8011/builders/ubuntu-gcc7.1-werror/builds/3369 for details. llvm-svn: 319602
2017-11-30Add visibility flag to Wasm symbol flagsSam Clegg1-1/+3
The LLVM "hidden" flag needs to be passed through the Wasm intermediate objects in order for the linker to apply it to the final Wasm object. The corresponding change in LLD is here: https://github.com/WebAssembly/lld/pull/14 Patch by Nicholas Wilson Differential Revision: https://reviews.llvm.org/D40442 llvm-svn: 319488
2017-10-23[wasm] readSection: Avoid reading past eof (fixes oss-fuzz #3219)Vedant Kumar1-3/+5
A wasm file crafted with a bogus section size can trigger an ASan issue in the DWARFObjInMemory constructor. Nip the problem in the bud when we read the wasm section. Found by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3219 Differential Revision: https://reviews.llvm.org/D38777 llvm-svn: 316357
2017-09-29[WebAssembly] Allow each data segment to specify its own alignmentSam Clegg1-6/+7
Also, add a flags field as we will almost certainly be needing that soon too. Differential Revision: https://reviews.llvm.org/D38296 llvm-svn: 314534
2017-09-26[WebAssembly] Model weakly defined symbols as wasm exportsSam Clegg1-13/+5
Previously these were being included as both imports and exports, with the import being satisfied by the export (or some strong symbol) at runtime. However proved unnecessary and actually complicated linking as it meant there was not a 1-to-1 mapping between a wasm function /global index and a linker symbol. Differential Revision: https://reviews.llvm.org/D38246 llvm-svn: 314245
2017-09-26[WebAssembly] Use function/global index space in WasmSymbolSam Clegg1-11/+9
It is useful for the symbol to contain the index of the function of global it represents in the function/global index space. For imports we also store the import index so that the linker can find, for example, the signature of the corresponding function, which is defined by the import In the long run we need to decide whether this API surface should be closer to binary (where imported functions are seperate) or the wasm spec (where the function index space is unified). Differential Revision: https://reviews.llvm.org/D38189 llvm-svn: 314230
2017-09-20[WebAssembly] Weak symbols should be defined in SF_GlobalSam Clegg1-1/+1
Summary: This manifested itself in lld since it meant that weak symbols were not appearing in archive symbol tables. Subscribers: jfb, dschuff, jgravelle-google, aheejin Differential Revision: https://reviews.llvm.org/D38111 llvm-svn: 313838
2017-09-20[WebAssembly] Add support for local symbol bindingsSam Clegg1-5/+9
Differential Revision: https://reviews.llvm.org/D38096 llvm-svn: 313817
2017-09-20Reland "[WebAssembly] Add support for naming wasm data segments"Sam Clegg1-0/+9
Add adds support for naming data segments. This is useful useful linkers so that they can merge similar sections. Differential Revision: https://reviews.llvm.org/D37886 llvm-svn: 313795
2017-09-20Reverting due to Green Dragon bot failure.Mike Edwards1-9/+0
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/42594/ llvm-svn: 313706
2017-09-19[WebAssembly] Add support for naming wasm data segmentsSam Clegg1-0/+9
Add adds support for naming data segments. This is useful useful linkers so that they can merge similar sections. Differential Revision: https://reviews.llvm.org/D37886 llvm-svn: 313692
2017-09-06[WebAssembly] Only treat imports/exports as symbols when reading relocatable ↵Sam Clegg1-33/+67
object files This change only treats imported and exports functions and globals as symbol table entries the object has a "linking" section (i.e. it is relocatable object file). In this case all globals must be of type I32 and initialized with i32.const. This was previously being assumed but not checked for and was causing a failure on big endian machines due to using the wrong value of then union. See: https://bugs.llvm.org/show_bug.cgi?id=34487 Differential Revision: https://reviews.llvm.org/D37497 llvm-svn: 312674
2017-09-01[WebAssembly] Update relocation names to match specSam Clegg1-3/+3
Summary: See https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md Differential Revision: https://reviews.llvm.org/D37385 llvm-svn: 312342
2017-09-01[WebAssembly] Fix getSymbolValue for exported globalsSam Clegg1-1/+1
The code wasn't previously taking into account that the global index space is not same as the into in the Globals array since the latter does not include imported globals. This fixes the WebAssembly waterfall failures. Differential Revision: https://reviews.llvm.org/D37384 llvm-svn: 312340
2017-08-31[WebAssembly] Fix getSymbolValue() for data symbolsSam Clegg1-1/+6
This is mostly a fix for the output of `llvm-nm` See Bug 34392: https://bugs.llvm.org//show_bug.cgi?id=34392 Differential Revision: https://reviews.llvm.org/D37359 llvm-svn: 312294
2017-08-31[WebAssembly] Validate exports when parsing object filesSam Clegg1-0/+8
Subscribers: jfb, dschuff, jgravelle-google, aheejin Differential Revision: https://reviews.llvm.org/D37358 llvm-svn: 312286
2017-08-23[WebAssembly] Fix overflow for input with missing versionJonas Devlieghere1-1/+9
Differential revision: https://reviews.llvm.org/D37070 llvm-svn: 311605
2017-07-12[WebAssembly] Expose the offset of each data segmentSam Clegg1-4/+6
Summary: This allows tools like lld that process relocations to apply data relocation correctly. This information is required because relocation are stored as section offset. Subscribers: jfb, dschuff, jgravelle-google, aheejin Differential Revision: https://reviews.llvm.org/D35234 llvm-svn: 307741
2017-07-07[WebAssembly] Support weak defined symbolsSam Clegg1-10/+20
Model weakly defined symbols as symbols that are both exports and imported and marked as weak. Local references to the symbols refer to the import but the linker can resolve this to the weak export if not strong symbol is found at link time. Differential Revision: https://reviews.llvm.org/D35029 llvm-svn: 307348
2017-06-27[WebAssembly] Add support for printing relocations with llvm-objdumpSam Clegg1-1/+4
Differential Revision: https://reviews.llvm.org/D34658 llvm-svn: 306461
2017-06-27[WebAssembly] Add data size and alignement to linking sectionSam Clegg1-1/+10
The overal size of the data section (including BSS) is otherwise not included in the wasm binary. Differential Revision: https://reviews.llvm.org/D34657 llvm-svn: 306459
2017-06-20[WebAssembly] Fix build failures introduced in r305769Sam Clegg1-0/+1
This fixes two build failures that only occur in certain configurations: - error: unused function 'operator<<' - error: control reaches end of non-void function Differential Revision: https://reviews.llvm.org/D34382 llvm-svn: 305770
2017-06-20[WebAssembly] Add support for weak symbols in the binary formatSam Clegg1-5/+83
This also introduces the updated format for the "linking" section which can represent extra symbol information. See: https://github.com/WebAssembly/tool-conventions/pull/10 Differential Revision: https://reviews.llvm.org/D34019 llvm-svn: 305769