Commit Graph

530 Commits

Author SHA1 Message Date
Stefan Gränitz 2131eb6963 [ORC] DebugObjectManagerPlugin tests can use lli in ORC greedy mode
Initially, lli only supported lazy mode for ORC. Greedy mode was added with e1579894d2 and it's the default setting now. DebugObjectManagerPlugin tests don't rely on laziness, so we can switch them to greedy in order to avoid some unnecessary complexity.
2021-09-22 18:26:52 +02:00
Stefan Gränitz 506dbd88fe [ORC] Re-enable ELF DebugObjectManagerPlugin tests
These tests were disabled by accident after D107640. Actually, REQUIRES lines don't support `x86_64` and so these tests stopped running on all targets.
`native && target-x86_64` should be the correct term to express "x86_64 host targeting native arch".
2021-09-22 17:55:46 +02:00
Moritz Sichert a0a5964499 [RuntimeDyld] Implemented relocation of TLS symbols in ELF
Differential Revision: https://reviews.llvm.org/D105466
2021-09-06 10:27:43 +02: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
Fangrui Song dfb7518df1 [MC] Set SHF_INFO_LINK on SHT_REL/SHT_RELA sections
sh_info links to a section, therefore SHF_INFO_LINK should be set as GNU as
does. The issue has been benign because linkers kindly combines relocation
sections w/ and w/o the flag.
2021-09-02 01:00:51 -07:00
luxufan 89f546f6ba [JITLink][RISCV] Support GOT/PLT relocations
This patch add the R_RISCV_GOT_HI20 and R_RISCV_CALL_PLT relocation support. And the basic got/plt was implemented. Because of riscv32 and riscv64 has different pointer size, the got entry size and instructions of plt entry is different. This patch is the basic support, the optimization pass at preFixup stage has not been implemented.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107688
2021-08-28 11:52:21 +08:00
luxufan dda116bc3d [JITLink] Add support of R_X86_64_32S relocation
This patch supported the R_X86_64_32S relocation and add the Pointer32Signed generic edge kind.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D108446
2021-08-22 16:45:25 +08:00
luxufan a9095f005f [JITLink] Optimize GOTPCRELX Relocations
This patch optimize the GOTPCRELX Reloations, which is described in X86-64 psabi chapter B.2. And Not all optimization of this chapter is implemented.

1. Convert call and jmp has been implemented
2. Convert mov, but the optimization that when the symbol is defined in the lower 32-bit address space, memory operand in `mov` can be convertted into immediate operand has not been implemented.
3. Conver Test and Binop has not been implemented.

The new test file named ELF_got_plt_optimizations.s has been added, and I moved some test cases about optimization of got/plt from ELF_x86_64_small_pic_relocations.s to the new test file.

By referencing the lld, so, the optimization `Convert call and jmp` is not same as what psabi says, and I have explained it in the comment.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D108280
2021-08-19 10:30:22 +08:00
Stefan Gränitz c5ab55f533 [Orc] Enable debug object tests only on x86_64 hosts
These tests rely on running IR code with an explicit x86_64 target triple. They won't work on other architectures. (They won't work for 32-bit processes on x86_64 hosts either. We will take care of this later.)

Differential Revision: https://reviews.llvm.org/D107640
2021-08-11 12:07:46 +02:00
luxufan dc9b41f3b4 [JITLink][RISCV] Add relocation fixup test
This patch add R_RISCV_HI20, R_RISCV_LO12 and R_RISCV_CALL relocation test

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107327
2021-08-06 14:35:59 +08:00
David Spickett b1802d694c [llvm][ExecutionEngine] Don't try to run tests on ARM64/Windows on Arm
We use CMAKE_SYSTEM_PROCESSOR to set the host_arch lit feature.
This is going to be the same value as CMAKE_HOST_SYSTEM_PROCESSOR,
which on windows is set to the value of the PROCESSOR_ARCHITECTURE
environment variable.

https://cmake.org/cmake/help/latest/variable/CMAKE_HOST_SYSTEM_PROCESSOR.html#cmake-host-system-processor

On Windows on Arm this is "ARM64", not "AArch64" as we currently
look for.

https://docs.microsoft.com/en-us/windows/win32/winprog64/wow64-implementation-details#environment-variables

Add ARM64 to the unsupported list.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D107361
2021-08-04 09:24:18 +00:00
luxufan f4e418ac1e [RuntimeDyldChecker] Support offset in decode_operand expr
In RISCV's relocations, some relocations are comprised of two relocation types. For example, R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO12_I compose a PC relative relocation. In general the compiler will set a label in the position of R_RISCV_PCREL_HI20. So, to test the R_RISCV_PCREL_LO12_I relocation, we need decode instruction at position of the label points to R_RISCV_PCREL_HI20 plus 4 (the size of a riscv non-compress instruction).

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D105528
2021-08-03 11:25:51 +08:00
Nico Weber 75077f46e7 [JITLink][RISCV] Run new test from 0ad562b48 only if the RISCV backend is enabled 2021-07-25 10:47:26 -04:00
luxufan 0ad562b48b [JITLink][RISCV] Initial Support RISCV64 in JITLink
This patch is the initial support, it implements translation from object file to JIT link graph, and very few relocations were supported. Currently, the test file ELF_pc_indirect.s is passed, the HelloWorld program(compiled with mno-relax flag) can be linked correctly and run on instruction emulator correctly.

In the downstream implementation, I have implemented the GOT, PLT function, and EHFrame and some optimization will be implement soon. I will organize the code in to patches, then gradually send it to upstream.

Differential Revision: https://reviews.llvm.org/D105429
2021-07-23 23:47:30 +08:00
Lang Hames ca4a938617 [JITLink][MachO] Detect MachO::S_THREAD_LOCAL_ZEROFILL sections as zero-fill.
This will be used in upcoming MachO native TLV support patches to LLVM and
the ORC runtime.
2021-07-21 09:10:10 +10:00
Lang Hames 89aa11ed28 [ORC] Remove LLVM-side MachO Platform runtime support.
Support for this functionality is moving to the ORC runtime.
2021-07-17 14:25:31 +10:00
Lang Hames 8e66fc4384 [JITLink][ELF] Move ELF section and symbol parsing into ELFLinkGraphBuilder.
Move architecture independent ELF parsing/graph-building code from
ELFLinkGraphBuilder_x86_64 to the ELFLinkGraphBuilder base class template.
2021-06-29 09:59:49 +10:00
Lang Hames fc3ca2cc08 [JITLink][MachO] Add missing testcase.
This test was accidentally left out of f9649d123d.
2021-06-13 20:43:49 +10:00
Lang Hames 249cd9dd60 [JITLink][MachO][arm64] Build GOT entries for defined symbols too.
During the generic x86-64 support refactor in ecf6466f01 the implementation
of MachO_arm64_GOTAndStubsBuilder::isGOTEdgeToFix was altered to only return
true for external symbols. This behavior is incorrect: GOT entries may be
required for defined symbols (e.g. in the large code model).

This patch fixes the bug and adds a test case for it (renaming an old test
case to avoid any ambiguity).
2021-05-25 12:19:09 -07:00
Lang Hames 2367a7bdab [JITLink][MachO][arm64] Use a more descriptive test name. 2021-05-25 12:19:08 -07:00
Yonghong Song 6a2ea84600 BPF: Add more relocation kinds
Currently, BPF only contains three relocations:
  R_BPF_NONE   for no relocation
  R_BPF_64_64  for LD_imm64 and normal 64-bit data relocation
  R_BPF_64_32  for call insn and normal 32-bit data relocation

Also .BTF and .BTF.ext sections contain symbols in allocated
program and data sections. These two sections reserved 32bit
space to hold the offset relative to the symbol's section.
When LLVM JIT is used, the LLVM ExecutionEngine RuntimeDyld
may attempt to resolve relocations for .BTF and .BTF.ext,
which we want to prevent. So we used R_BPF_NONE for such relocations.

This all works fine until when we try to do linking of
multiple objects.
  . R_BPF_64_64 handling of LD_imm64 vs. normal 64-bit data
    is different, so lld target->relocate() needs more context
    to do a correct job.
  . The same for R_BPF_64_32. More context is needed for
    lld target->relocate() to differentiate call insn vs.
    normal 32-bit data relocation.
  . Since relocations in .BTF and .BTF.ext are set to R_BPF_NONE,
    they will not be relocated properly when multiple .BTF/.BTF.ext
    sections are merged by lld.

This patch intends to address this issue by adding additional
relocation kinds:
  R_BPF_64_ABS64     for normal 64-bit data relocation
  R_BPF_64_ABS32     for normal 32-bit data relocation
  R_BPF_64_NODYLD32  for .BTF and .BTF.ext style relocations.
The old R_BPF_64_{64,32} semantics:
  R_BPF_64_64        for LD_imm64 relocation
  R_BPF_64_32        for call insn relocation

The existing R_BPF_64_64/R_BPF_64_32 mapping to numeric values
is maintained. They are the most common use cases for
bpf programs and we want to maintain backward compatibility
as much as possible.

ExecutionEngine RuntimeDyld BPF relocations are adjusted as well.
R_BPF_64_{ABS64,ABS32} relocations will be resolved properly and
other relocations will be ignored.
Two tests are added for RuntimeDyld. Not handling R_BPF_64_NODYLD32 in
RuntimeDyldELF.cpp will result in "Relocation type not implemented yet!"
fatal error.

FK_SecRel_4 usages in BPFAsmBackend.cpp and BPFELFObjectWriter.cpp
are removed as they are not triggered in BPF backend.
BPF backend used FK_SecRel_8 for LD_imm64 instruction operands.

Differential Revision: https://reviews.llvm.org/D102712
2021-05-25 08:19:13 -07:00
Lang Hames 0c6ee502eb [JITLink] Add testcase that was accidentally left out of 19e402d2b3. 2021-04-17 11:55:55 -07:00
Stefan Gränitz 243fe0da99 [lli] Leaving two EH frame tests with MCJIT only after PowerPC failure
Will investigate these in isolation once the rest of D98931 successfully landed.
2021-03-30 12:28:22 +02:00
Stefan Gränitz c42c67ad60 Re-apply "[lli] Make -jit-kind=orc the default JIT engine"
MCJIT served well as the default JIT engine in lli for a long time, but the code is getting old and maintenance efforts don't seem to be in sight. In the meantime Orc became mature enough to fill that gap. The newly added greddy mode is very similar to the execution model of MCJIT. It should work as a drop-in replacement for common JIT tasks.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D98931
2021-03-30 12:08:26 +02:00
Stefan Gränitz c352a2b829 [lli] Add option -lljit-platform=Inactive to disable platform support explicitly
This option tells LLJIT to disable platform support explicitly: JITDylibs aren't scanned for special init/deinit symbols and no runtime API interposes are injected.
It's useful in two cases: for platforms that don't have such requirements and platforms for which we have no explicit support yet and that don't work well with the generic IR platform.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D99416
2021-03-30 09:29:45 +02:00
Stefan Gränitz 66a8247eb6 [Orc][tests] Moving one MCJIT test over to Orc to make sure the PowerPC fix worked
The PowerPC fix landed in d9069dd9b5. This is in preparation for D98931.
2021-03-29 11:53:03 +02:00
Lang Hames 19e402d2b3 [JITLink][MachO] Use full <segment>,<section> names for MachO jitlink::Sections.
JITLink now requires section names to be unique. In MachO section names are only
guaranteed to be unique within their containing segment (e.g. a '__const' section
in the '__DATA' segment does not clash with a '__const' section in the '__TEXT'
segment), so we need to use the fully qualified <segment>,<section> section
names (e.g. '__DATA,__const' or '__TEXT,__const') when constructing
jitlink::Sections for MachO objects.
2021-03-25 18:31:18 -07:00
Stefan Gränitz 581adb4f1a Temporarily revert "[lli] Make -jit-kind=orc the default JIT engine"
This reverts commit eaee4f2696.
2021-03-23 12:01:30 +01:00
Stefan Gränitz eccd7ae2fd [lli] Fix ppc64le-clang-lnt-test bot: Keep test-call.ll a MCJIT-only test
No callback manager available for powerpc64le-unknown-linux-gnu
2021-03-23 10:47:57 +01:00
Stefan Gränitz eaee4f2696 [lli] Make -jit-kind=orc the default JIT engine
MCJIT served well as the default JIT engine in lli for a long time, but the code is getting old and maintenance efforts don't seem to be in sight. In the meantime Orc became mature enough to fill that gap. The newly added greddy mode is very similar to the execution model of MCJIT. It should work as a drop-in replacement for common JIT tasks.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D98931
2021-03-23 10:22:34 +01:00
Lang Hames cc4ad2c540 [JITLink][ELF/x86-64] Add support for GOTOFF64 relocation. 2021-03-22 10:40:50 -07:00
Lang Hames fc36a511c6 [JITLink][ELF/x86-64] Add support for R_X86_64_GOTPC64 and R_X86_64_GOT64.
Start adding support for ELF x86-64 large code model, PIC relocations.
2021-03-21 21:52:54 -07:00
Lang Hames 1237d94871 [JITLink] Add support for STT_NOTYPE symbols to ELF/x86-64. 2021-03-09 20:40:24 -08:00
Stefan Gränitz 6a3a386c6f [Orc] Test DebugObjectManagerPlugin fills in load-address for .text section of in-memory ELF debug object 2021-03-09 14:01:50 +01:00
Stefan Gränitz ae51fde369 [Orc] Extend lli debug support tests to JITLink 2021-03-02 15:07:36 +01:00
Stefan Gränitz f47ff8cff1 [lli] Test debug support in RuntimeDyld with built-in functions
When lli runs the below IR, it emits in-memory debug objects and registers them with the GDB JIT interface. The tests dump and check the registered information. IR has limited ability to produce complex output in a portable way. Instead the tests rely on built-in functions implemented in lli. They use a new command line flag `-generate=function-name` to instruct the ORC JIT to expose the built-in function with the given name to the JITed program.

`debug-descriptor-elf-minimal.ll` calls `__dump_jit_debug_descriptor()` to reflect the list of debug entries issued for itself after emitting the main module. The output is textual and can be checked straight away.

`debug-objects-elf-minimal.ll` calls `__dump_jit_debug_objects()`, which instructs lli to walk through the list of debug entries and append the encountered in-memory objects to the program output. We feed this output into llvm-dwarfdump to parse the DWARF in each file and dump their structures.

We can do the same for JITLink once D97335 has landed.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D97694
2021-03-02 10:39:09 +01:00
Lang Hames d2bb07949b Revert "[JITLink] Add missing symbols for ELF ehframe testcase, re-enable ...."
This reverts commit 6e58539659.

This failed in http://lab.llvm.org:8011/#/builders/123/builds/2676. I guess
were're still missing some symbols, but unfortunately the specific error is
masked by a bug in python/lit that hides stderr. This test will have to remain
disabled on Windows until I can get help to debug it further.
2021-02-01 13:32:11 +11:00
Lang Hames 6e58539659 [JITLink] Add missing symbols for ELF ehframe testcase, re-enable on Windows.
This testcase was failing on windows due to missing definitions. This commit
adds definitions of the missing symbols (as absolute symbols) to eliminate the
errors.
2021-02-01 12:24:24 +11:00
Lang Hames 236b0d0407 [JITLink] Disable ELF_ehframe_basic.s test on Windows.
This test is failing on some windows bots with an error claiming that it is not
producing output. This appears to be a spurious failure, so I'm disabling on
windows while we investigate rather than reverting.
2021-01-26 13:58:38 +11:00
Lang Hames cda4d3d37f [JITLink] Re-apply 6884fbc2c4 (ELF eh support) with fix for broken test case. 2021-01-26 11:55:41 +11:00
Nico Weber f80782590c Revert "[JITLink] Enable exception handling for ELF."
This reverts commit 6884fbc2c4.
Breaks tests on Windows: http://45.33.8.238/win/31981/step_11.txt
2021-01-25 11:00:38 -05:00
Lang Hames 6884fbc2c4 [JITLink] Enable exception handling for ELF.
Adds the EHFrameSplitter and EHFrameEdgeFixer passes to the default JITLink
pass pipeline for ELF/x86-64, and teaches EHFrameEdgeFixer to handle some
new pointer encodings.

Together these changes enable exception handling (at least for the basic
cases that I've tested so far) for ELF/x86-64 objects loaded via JITLink.
2021-01-25 15:31:27 +11:00
Lang Hames 3b1f17ca54 [JITLink][ELF/x86-64] Add support for weak and hidden symbols. 2021-01-22 20:51:11 +11:00
Lang Hames e5619065b8 [JITLink][ELF] New ELF skip-debug-sections test requires asserts.
This should fix the failures on Release mode testers.
2021-01-18 15:41:53 +11:00
Lang Hames a817f46d50 [JITLink][ELF] Skip DWARF sections in ELF objects.
This matches current JITLink/MachO behavior and avoids processing currently
unsupported relocations.
2021-01-18 12:42:48 +11:00
Stefan Gränitz 694c16a823 [JITLink][ELF] Omit temporary labels in tests
Oneshot temporary labels for declaring function size can be omitted. Follow-up from D90331.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D90676
2020-11-04 10:03:15 +00:00
Stefan Gränitz b397795f1a [JITLink][ELF] Implement R_X86_64_PLT32 relocations
Basic implementation for call and jmp branches with 32 bit offset. Branches to local targets produce
Branch32 edges that are resolved like a regular PCRel32 relocations. Branches to external (undefined)
targets produce Branch32ToStub edges and go through a PLT entry by default. If the target happens to
get resolved within the 32 bit range from the callsite, the edge is relaxed during post-allocation
optimization. There is a test for each of these cases.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D90331
2020-11-03 12:05:54 +00:00
Stefan Gränitz 66abe650ff Reapply "[jitlink][ELF] Add zero-fill blocks for symbols in section SHN_COMMON"
Root cause of the test failure was fixed with:
[JITLink][ELF] PCRel32GOTLoad edge offset can be smaller three

This reverts commit 10b1a61baf.
2020-10-24 16:58:06 +02:00
Stefan Gränitz 10b1a61baf Revert "[jitlink][ELF] Add zero-fill blocks for symbols in section SHN_COMMON"
This reverts commit e9955b0843. Cannot reproduce the buildbot failures yet. Reverting in the meantime.
2020-10-24 15:43:06 +02:00
Stefan Gränitz e9955b0843 [jitlink][ELF] Add zero-fill blocks for symbols in section SHN_COMMON
Symbols with special section index SHN_COMMON (0xfff2) haven't been handled so far and caused an invalid section error.

This is a more or less straightforward use of the code commented out at the end of the function. I checked with the ELF spec, that the symbol value gives the alignment.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D89795
2020-10-24 14:54:38 +02:00