Commit Graph

140 Commits

Author SHA1 Message Date
Lang Hames 6db0807c2c [JITLink] Suppress "symbols not found" errors for testcase.
On some platforms _ZTIi may not be present (see discussion at
https://reviews.llvm.org/rG43acef48d38e). We don't need this symbol for the
test to work, so just add -phony-externals to the testcase to suppress the
error.
2022-04-17 08:34:22 -07:00
Lang Hames 43acef48d3 [JITLink] Refactor and expand DWARF pointer encoding support.
Adds support for pointer encodings commonly used in large/static models,
including non-pcrel, sdata/udata8, indirect, and omit.

Also refactors pointer-encoding handling to consolidate error generation inside
common functions, rather than callees of those functions.
2022-04-15 12:51:46 -07:00
Lang Hames 9a62d9db2e [JITLink][MachO] Fix alignment bug in the c-string literal section graphifier.
This function had been assuming a 1-byte alignment, which isn't always correct.
This commit updates it to take the alignment from the __cstring section.

The key change is to the createContentBlock call, but the surrounding code is
updated with clearer debugging output to support the testcase (and any future
debugging work).
2022-04-05 17:38:54 -07:00
Lang Hames 01bc5b7034 [JITLink] Fix sorting bug for PC-begin candidate symbols during EH-frame fixup.
The sort should have been lexicographic, but wasn't. This resulted in us
choosing a common symbol at address zero over the intended target function,
leading to a crash.

This patch also moves sorting up to the start of the pass, which means that we
only need to hold on to the canonical symbol at each address rather than a list
of candidates.
2022-04-05 13:02:28 -07:00
Shubham Sandeep Rastogi 229d576b31 Rename EHFrameSplitter to DWARFRecordSectionSplitter
EHFrameSplitter does the exact same work to split up the eh_frame as it would need for any section that follows the DWARF record, therefore this patch just changes the name of it to DWARFRecordSectionSplitter to be more general.

Differential Revision: https://reviews.llvm.org/D121486
2022-03-11 16:02:31 -08:00
Lang Hames 151f809c55 [JITLink] Demote symbol scope to local during external-to-absolute conversion.
When an external symbol is converted to an absolute it should be demoted to
local scope so that the symbol does not become a new definition within this
LinkGraph.
2022-03-08 10:31:20 -08:00
Lang Hames 36f0dfd07a [ORC][JITLink] Fix MachO absolute symbol handling, add test case.
This patch removes the unintended resolution of locally scoped absolute symbols
(which was causing unexpected definition errors).

It stops using the JITSymbolFlags::Absolute flag (it isn't set or used elsewhere,
and causes mismatch-flags asserts), and adds JITSymbolFlags::Exported to default
scoped absolute symbols.

Finally, we now set the scope of absolute symbols correctly in
MachOLinkGraphBuilder.
2022-03-07 20:54:55 -08:00
luxufan 3362f54d08 [JITLink] Add R_RISCV_SUB6 relocation
Add R_RISCV_SUB6 relocation

Differential Revision: https://reviews.llvm.org/D120001
2022-03-01 01:45:03 +08:00
fourdim 1ece3eeeb7 [JITLink][RISCV] fix the extractBits behavior and add R_RISCV_JAL relocation.
This patch supports the R_RISCV_JAL relocation.
Moreover, it will fix the extractBits function's behavior as it extracts Size + 1 bits.
In the test ELF_jal.s:
Before:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 480
```
After:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 224
```

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D117975
2022-02-18 14:07:28 +08:00
fourdim 051f7cdcd2 Revert "[JITLink][RISCV] fix the extractBits behavior and add R_RISCV_JAL relocation."
This reverts commit 3af7bbca4a.
2022-02-17 23:40:32 +08:00
fourdim 3af7bbca4a [JITLink][RISCV] fix the extractBits behavior and add R_RISCV_JAL relocation.
This patch supports the R_RISCV_JAL relocation.
Moreover, it will fix the extractBits function's behavior as it extracts Size + 1 bits.
In the test ELF_jal.s:
Before:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 480
```
After:
```
Hi: 4294836480
extractBits(Hi, 12, 8): 224
```

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D117975
2022-02-17 23:03:36 +08:00
luxufan 9920943ea2 [JITLink] Fix the incorrect relocation behavior for R_RISCV_BRANCH
In D116573, the relocation behavior of R_RISCV_BRANCH didn't consider that branch instruction like 'bge' has a branch target address which is given as a PC-relative offset, sign-extend and multiplied by 2.
Although the target address is a 12-bits number, acctually its range is [-4096, 4094].

This patch fix it.

Differential Revision: https://reviews.llvm.org/D118151
2022-02-07 14:34:19 +08:00
Lang Hames 67a9f82cc9 [llvm-jitlink] Add comment to clarify testcase intent. 2022-02-03 18:59:09 +11:00
Lang Hames 517a4844bf [llvm-jitlink] Add -alias option, shorten "-define-abs" option to "-abs".
The -alias option can be used to define aliases within a JITDylib. The
immediate motivation is to simplify testing of ORC runtime functions using
existing testcases (e.g. by aliasing dlfcn functions to their ORC-runtime
counterparts, like -alias dlopen=__orc_rt_macho_dlopen). The option is likely
to be useful for testing in general.

The -define-abs option is shortened to -abs for consistency with -alias.
2022-02-03 18:47:59 +11:00
luxufan 0283b07746 reapply de87238295 "[JITLink] Add anonymous symbols in LinkGraph..."
with fixes

This reapply `de872382951572b70dfaefe8d77eb98d15586115`, which was
reverted in `fdb6578514dd3799ad23c8bbb7699577c0fb414d`

Add `# REQUIRES: asserts` in test file `anonymous_symbol.s` to disable
this test for non-debug build
2022-01-22 20:50:36 +08:00
fourdim f7d4cafe5a [JITLink][RISCV] Support R_RISCV_SET* and R_RISCV_32_PCREL relocations
This patch supports R_RISCV_SET* and R_RISCV_32_PCREL relocations in JITLink.

Reviewed By: StephenFan

Differential Revision: https://reviews.llvm.org/D117082
2022-01-22 03:34:51 +08:00
luxufan fdb6578514 Revert "[JITLink] Add anonymous symbols in LinkGraph for unnamed temporary symbols"
This reverts commit de87238295.

Buildbot check error
2022-01-22 17:26:54 +08:00
luxufan de87238295 [JITLink] Add anonymous symbols in LinkGraph for unnamed temporary symbols
In RISCV, temporary symbols will be used to generate dwarf, eh_frame sections..., and will be placed in object code's symbol table. However, LLVM does not use names on these temporary symbols. This patch add anonymous symbols in LinkGraph for these temporary symbols.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D116475
2022-01-22 16:47:39 +08:00
luxufan dc18c5fa97 [JITLink] Add RISCV label subtraction and addition relocations
This patch add RISCV label subtraction and addition relocations in JITLink

Differential Revision: https://reviews.llvm.org/D116794
2022-01-19 22:12:56 +08:00
Steven Wu 091e364866 [JITLink][ELF] Support duplicated section names from object file
ELF object files can contain duplicated sections (thus section symbols
as well), espeically when comdats/section groups are present. This patch
adds support for generating LinkGraph from object files that have
duplicated section names. This is the first step to properly model
comdats/section groups.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D114753
2022-01-18 08:38:28 -08:00
Ben Langmuir ca2353ce5a Teach llvm-jitlink to support archives in inputs files and -load_hidden
Similar to the ld64 command-line options. These use the same underlying
mechanisms as -l and -hidden-l, but allow specifying an absolute path to
the archive. This is often more convenient for a one-off, or when adding
a new search path could change how existing -l options are resolved.

Differential Revision: https://reviews.llvm.org/D117360
2022-01-14 16:27:51 -08:00
fourdim 0c6f762622 [jitlink] add R_RISCV_BRANCH to jitlink
This patch supported the R_RISCV_BRANCH relocation.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D116573
2022-01-15 03:36:58 +08:00
Lang Hames bfd0cbd4eb Reapply 253ce92844 "[JITLink][AArch64] Add support for splitting.." with fixes.
This reapplies 253ce92844, which was reverted in
66b2ed477f due to bot failures.

I have added the `-phony-externals` option added, which should fix the
unresolved symbol errors.
2022-01-14 10:00:20 +11:00
luxufan 0ef5aa69e7 [JITLink] Add fixup value range check
This patch makes jitlink to report an out of range error when the fixup value out of range

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107328
2022-01-13 16:32:49 +08:00
Nico Weber 66b2ed477f Revert "[JITLink][AArch64] Add support for splitting eh-frames on AArch64."
This reverts commit 253ce92844.
Breaks tests on Windows, see
https://github.com/llvm/llvm-project/issues/52921#issuecomment-1011118896
2022-01-12 14:40:09 -05:00
Lang Hames 253ce92844 [JITLink][AArch64] Add support for splitting eh-frames on AArch64.
This is needed for DWARF eh-frame exception handling on AArch64.

https://github.com/llvm/llvm-project/issues/52921.

Original patch by David Nadlinger <code@klickverbot.at> (thanks David!),
testcase and comments added by me.
2022-01-12 20:42:36 +11:00
Lang Hames 1f3d4525d8 [JITLink][AArch64] Use R-X permissions for the GOT.
This consistent with ld64's treatment of the GOT, but the main aim here is a
short-term workaround for a bad interaction between stub code sequences and
memory layout: Stubs use LDRLiteral19 relocations to reference the GOT, but
BasicLayout currently puts RW- segments between R-- and R-X segments -- a large
RW- segment (or a large R-- for that matter) can cause the relocation to fail
with an out-of-range error.

Putting the GOT in R-X fixes this efficiently in practice. A more robust fix
will be to use a longer code sequence to materialize the GOT pointer and then
rewrite the stub to use a shorter sequence where possible.
2022-01-12 18:03:58 +11:00
Nico Weber 085f078307 Revert "Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`.""
This reverts commit 859ebca744.
The change contained many unrelated changes and e.g. restored
unit test failes for the old lld port.
2022-01-05 13:10:25 -05:00
David Salinas 859ebca744 Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`."
This reverts commit 640beb38e7.

That commit caused performance degradtion in Quicksilver test QS:sGPU and a functional test failure in (rocPRIM rocprim.device_segmented_radix_sort).
Reverting until we have a better solution to s_cselect_b64 codegen cleanup

Change-Id: Ibf8e397df94001f248fba609f072088a46abae08

Reviewed By: kzhuravl

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

Change-Id: Id169459ce4dfffa857d5645a0af50b0063ce1105
2022-01-05 17:57:32 +00:00
luxufan 43c5fffcef Revert "[JITLink] Add fixup value range check"
This reverts commit 17af06ba80.
2022-01-05 00:04:09 +08:00
luxufan 17af06ba80 [JITLink] Add fixup value range check
This patch makes jitlink to report an out of range error when the fixup value out of range

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107328
2022-01-04 22:45:15 +08:00
Lang Hames 02fc8d5c9e [ORC] Add custom object interface support to StaticLibaryDefinitionGenerator.
This adds a GetObjectFileInterface callback member to
StaticLibraryDefinitionGenerator, and adds an optional argument for initializing
that member to StaticLibraryDefinitionGenerator's named constructors. If not
supplied, it will default to getObjectFileInterface from ObjectFileInterface.h.

To enable testing a `-hidden-l<x>` option is added to the llvm-jitlink tool.
This allows archives to be loaded with all contained symbol visibilities demoted
to hidden.

The ObjectLinkingLayer::setOverrideObjectFlagsWithResponsibilityFlags method is
(belatedly) hooked up, and enabled in llvm-jitlink when `-hidden-l<x>` is used
so that the demotion is also applied at symbol resolution time (avoiding any
"mismatched symbol flags" crashes).
2021-12-16 19:46:51 +11:00
Lang Hames 5255ca9726 [llvm-jitlink] Update handling of library options.
Adds -L<search-path> and -l<library> options that are analogous to ld's
versions.

Each instance of -L<search-path> or -l<library> will apply to the most recent
-jd option on the command line (-jd <name> creates a JITDylib with the given
name). Library names will match against JITDylibs first, then llvm-jitlink will
look through the search paths for files named <search-path>/lib<library>.dylib
or <search-path>/lib<library>.a.

The default "main" JITDylib will link against all JITDylibs created by -jd
options, and all JITDylibs will link against the process symbols (unless
-no-process-symbols is specified).

The -dlopen option is renamed -preload, and will load dylibs into the JITDylib
for the ORC runtime only.

The effect of these changes is to make it easier to describe a non-trivial
program layout to llvm-jitlink for testing purposes. E.g. the following
invocation describes a program consisting of three JITDylibs: "main" (created
implicitly) containing main.o, "Foo" containing foo1.o and foo2.o, and linking
against library "bar" (not a JITDylib, so it must be a .dylib or .a on disk)
and "Baz" (which is a JITDylib), and "Baz" containing baz.o.

llvm-jitlink \
  main.o \
  -jd Foo foo1.o foo2.o -L${HOME}/lib -lbar -lBaz
  -jd Baz baz.o
2021-12-15 13:49:30 +11:00
Lang Hames 02095f2dd7 [ORC] Pad section start to account for alignment offset in MachO GDB JIT plugin.
In order to present a well-formed MachO debug object for debugger registration
the first block in each section must have a zero alignment offset (since there
is no way to represent a non-zero offset in a MachO section load command). This
patch updates the MachODebugObjectSynthesizer class to introduce a padding
padding block at the start of the section if necessary to guarantee a zero
alignment offset.
2021-12-07 14:28:31 +11:00
Lang Hames 21562c03ed [JITLink][ELF][x86-64] Adjust addends for R_X86_64_PLT32 relocations.
R_X86_64_PLT32 explicitly represents the '-4' PC-adjustment in the relocation's
addend, but JITLink's x86_64::Branch32PCRel includes the PC-adjustment
implicitly. We have been zeroing the addend to account for the difference, but
this breaks for branches to non-zero offsets past labels. This patch updates the
relocation parsing code to unconditionally adjust the offset by '+4' instead.
For branches directly to labels the result is still 0, for branches to offsets
past labels the result is the correct addend for x86_64::Branch32PCRel.
2021-12-05 20:37:55 +11:00
Steven Wu c737d4d203 [JITLink][ELF] Don't skip sections of size 0
Size 0 sections can have symbols that have size 0. Build those sections
and symbols into the LinkGraph so they can be used properly if needed.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D114749
2021-11-30 09:19:14 -08:00
Steven Wu 5e3200f3ce [JITLink][ELF] Add support for reading extended table
Add support for reading extended table in ELF object file. This allows
JITLink to support ELF object files with many sections.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D114747
2021-11-30 09:18:42 -08:00
Ben Langmuir 4c94760f36 [ORC] Fix materialization of weak local symbols
We were adding all defined weak symbols to the materialization
responsibility, but local symbols will not be in the symbol table, so it
failed to materialize due to the "missing" symbol.

Local weak symbols come up in practice when using `ld -r` with a hidden
weak symbol.

rdar://85574696
2021-11-19 07:25:56 -08:00
Ben Langmuir 5273773580 [JITLink] Allow duplicate symbol names for locals
Local symbols can have the same name. I ran into this with JITLink
while working with an object file that had been run through `strip -S`
that had many "func.eh" symbols, but it can also happen using `ld -r`.

rdar://85352156

Differential Revision: https://reviews.llvm.org/D114042
2021-11-17 09:31:51 -08:00
Lang Hames 55751f5f63 [llvm-jitlink] Add an explicit -debugger-support option.
Commit 69be352a19 restricted the MachO debugger support testcase to run on
Darwin only, but we still need to disable debugger support by default for
other noexec tests.

This patch introduces a -debugger-support option to llvm-jitlink that is
on-by-default when executing code, and off-by-default for noexec tests. This
should prevent regression tests from trying (and failing) to set up MachO
debugging support when running on non-Darwin platforms.

to explicitly enable/disable support.
2021-11-14 15:46:00 -08:00
Lang Hames 69be352a19 Reapply "[ORC] Initial MachO debugging support (via GDB JIT debug.." with fixes.
This reapplies e1933a0488 (which was reverted in
f55ba3525e due to bot failures, e.g.
https://lab.llvm.org/buildbot/#/builders/117/builds/2768).

The bot failures were due to a missing symbol error: We use the input object's
mangling to decide how to mangle the debug-info registration function name. This
caused lookup of the registration function to fail when the input object
mangling didn't match the host mangling.

Disbaling the test on non-Darwin platforms is the easiest short-term solution.
I have filed https://llvm.org/PR52503 with a proposed longer term solution.
2021-11-14 14:44:07 -08:00
Lang Hames f55ba3525e Revert "[ORC] Initial MachO debugging support (via GDB JIT debug..."
This reverts commit e1933a0488 until I can look
into bot failures.
2021-11-14 00:14:39 -08:00
Lang Hames e1933a0488 [ORC] Initial MachO debugging support (via GDB JIT debug registration interface)
This commit adds a new plugin, GDBJITDebugInfoRegistrationPlugin, that checks
for objects containing debug info and registers any debug info found via the
GDB JIT registration API.

To enable this registration without redundantly representing non-debug sections
this plugin synthesizes a new embedded object within a section of the LinkGraph.
An allocation action is used to make the registration call.

Currently MachO only. ELF users can still use the DebugObjectManagerPlugin. The
two are likely to be merged in the near future.
2021-11-13 13:21:01 -08:00
Lang Hames 2272ec1c63 [JITLink][MachO] Fix "find-symbol-by-address" logic.
Only search within the requested section, and allow one-past-then-end addresses.

This is needed to support section-end-address references to sections with no
symbols in them.
2021-11-12 21:28:32 -08:00
Ben Langmuir a2639dcbe6 [ORC] Add a utility for adding missing "self" relocations to a Symbol
If a tool wants to introduce new indirections via stubs at link-time in
ORC, it can cause fidelity issues around the address of the function if
some references to the function do not have relocations. This is known
to happen inside the body of the function itself on x86_64 for example,
where a PC-relative address is formed, but without a relocation.

```
_foo:
  leaq -7(%rip), %rax ## form pointer to '_foo' without relocation

_bar:
  leaq (%rip), %rax ##  uses X86_64_RELOC_SIGNED to '_foo'
```

The consequence of introducing a stub for such a function at link time
is that if it forms a pointer to itself without relocation, it will not
have the same value as a pointer from outside the function. If the
function pointer is used as a key, this can cause problems.

This utility provides best-effort support for adding such missing
relocations using MCDisassembler and MCInstrAnalysis to identify the
problematic instructions. Currently it is only implemented for x86_64.

Note: the related issue with call/jump instructions is not handled
here, only forming function pointers.

rdar://83514317

Differential revision: https://reviews.llvm.org/D113038
2021-11-04 15:01:05 -07:00
Lang Hames 2167bc1b05 [JITLink][MachO][arm64] Make testcase less brittle.
The operand value is sign extended, so the test broke when sections were
re-ordered. The new test should be robust to reorderings.
2021-10-05 19:58:34 -07:00
Lang Hames 1f2f1a4414 [JITLink][MachO][x86-64] Add support for splitting compact-unwind sections.
Follow-up to fc734da795 to enable compact-unwind splitting on x86-64.
2021-09-28 19:12:56 -07:00
Lang Hames fc734da795 [JITLink][MachO][arm64] Add support for splitting compact-unwind sections.
CompactUnwindSplitter splits compact-unwind sections on record boundaries and
adds keep-alive edges from target functions back to their respective records.

In MachO_arm64.cpp, a CompactUnwindSplitter pass is added to the pre-prune pass
list when setting up the standard pipeline.

This patch does not provide runtime support for compact-unwind, but is a first
step towards enabling it.
2021-09-28 17:29:05 -07:00
Lang Hames abab0dbde2 [llvm-jitlink] Add -slab-page-size to tests that need it.
Also fixes 80-column rule violations.
2021-09-28 13:15:54 -07:00
Stefan Gränitz 2ed91da0f1 [JITLink] Add initial Aarch64 support
Set up basic infrastructure for 64-bit ARM architecture support in JITLink. It allows for loading a minimal object file and resolving a single relocation. Advanced features like GOT and PLT handling or relaxations were intentionally left out for the moment.

This patch follows the idea to keep implementations for ARM (32-bit) and Aaarch64 (64-bit) separate, because:
* it might be easier to share code with the MachO "arm64" JITLink backend
* LLVM has individual targets for ARM and Aaarch64 as well

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D108986
2021-09-03 10:48:06 +02:00