<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/93049>93049</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
TestImportStdModule.py fails on Linux AArch64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lldb,
platform:linux
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dzhidzhoev
</td>
</tr>
</table>
<pre>
The `lldb/test/API/commands/expression/import-std-module/basic/TestImportStdModule.py` test seems to fail on Linux AArch64 (Ubuntu).
The problem can be reproduced this way using the sample program from the test:
```
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Test" << std::endl;
return 0; // Set break point at this line.
}
```
If we compile it and run lldb, it fails after jumping to an illegal instruction:
```
(lldb) file a.out
Current executable set to 'a.out' (aarch64).
(lldb) settings set target.import-std-module true
(lldb) b main.cpp:6
Breakpoint 1: where = a.out`main + 68 at main.cpp:6:3, address = 0x0000000000000f58
(lldb) r
Process 274596 launched: 'a.out' (aarch64)
Process 274596 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000aaaaaaaa0f58 a.out`main(argc=1, argv=0x0000ffffffffeed8) at main.cpp:6:3
3
4 int main(int argc, char **argv) {
5 std::cout << "Test" << std::endl;
-> 6 return 0; // Set break point at this line.
7 }
(lldb) expr --unwind-on-error 0 -- std::minmax<int>(1, 2).first
error: Execution was interrupted, reason: signal SIGILL: illegal opcode.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
Process 274596 stopped
* thread #1, name = 'a.out', stop reason = signal SIGILL: illegal opcode
frame #0: 0x0000fffff7fef124
-> 0xfffff7fef120: udf #0x0
0xfffff7fef124: udf #0x0
0xfffff7fef128: udf #0x0
0xfffff7fef12c: udf #0x0
(lldb)
```
It seems to be a problem with relocations of jitted code. When LLDB jit-compiles an expression, it chooses to split jitted code into a separate section for each function from LLVM IR.
In the provided example, the buggy jump is a call from `_Z12$__lldb_exprPv` (entry function for expressions_ to `_ZNSt3__16minmaxB8sn190000IiEENS_4pairIRKT_S4_EES4_S4_`.
The relocation for this call is resolved correctly for code in lldb process address space, and it is represented as `_Z12$__lldb_exprPv function address + value`, where value is `call pc + "std::minmax<>" addr -_Z12$__lldb_exprPv addr`. "std::minmax<>" is located in a different section from _Z12$__lldb_exprPv, since all function are located in separate sections.
After jitted code sections are copied into the target's memory, the offset between "std::minmax<>" text section and `_Z12$__lldb_exprPv` changes, but the "value" of relocation isn't recalculated, which causes a jump the address 16 bytes less than the actual function address in my environment.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V12v4jjS_jXmpgQKTghwwQXng1foPTNqzendlfYGOU6FuNexI9vhwPz6VTkB0nPo3tGsNmo1J7br66mnqhzhvToaxA1bPLHFy0R0obZuU_5eq_L32uJpUtjysvlaI7A80bosGN8F9IHx3fbLnvGdtE0jTOkZ3-G5dei9sobxnWpa68LUh3La2LLTyPiuEF5Jxndf0Yd93H8P5S9xd9ZeWJ4AqQaP2HgIFiqhNFgDb8p0Z9hunazzDBhf_a3oTOgYX89Y8sKSbf8_edk6W2hsQAoDBYLD1tmyk1hCqJWHD3GBzitzhFAjeNG0OsocnWigcraJ6zHAdNDK8mT417_yVBmpuxKBpc_K-uBQNCx9HXuiTIBGKMP4iv4U7igZfwZZCweMbxnfCnc8Mb4GtnzqRQB8KMloupW2C6Scpc_AOP8a4ebXldsxNKVm6U3cYeicgYSlT8D4jvEdvGOAwqH4F7Q2-hF6FLQyeEVu-fIwzH0FHwjSNq3SCCqAMCW4zkDPgWdaovR4EFVAB9-6po2wWhAGlNZ4FBqU8cF1MhAlfojnqle5hopMiZntQr_13DmHJgCeUXZBFBrBYyATjC_7c3xJdBAiMmPEh7tSjyEoc_S9qHBHDLNP3ITgOvwkWsQczmTbsnSb99tPBGeP5pylW_io0RETXgbH84RkgPEnyFcE-Hcq0m1K2ImypEKJYsk5GT_VYvXJD9evf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