<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65734>65734</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AArch64] StringSaver::save(StringRef S) Segmentation fault
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wingrez
</td>
</tr>
</table>
<pre>
I ran into a problem using the llvm15 version of `lld`.
It reports a segmentation fault in the function `StringRef StringSaver::save(StringRef S)`.
More specifically, the error was reported inside memcpy.
```
StringRef StringSaver::save(StringRef S) {
char *P = Alloc.Allocate<char>(S.size() + 1);
if (!S.empty())
memcpy(P, S.data(), S.size());
P[S.size()] = '\0';
return StringRef(P, S.size());
}
```
Through debugging, I found that it was trying to write to an unwritable memory.
This is that crashing instruction. It is writing the value of `w2` to the position of `x19+w0`.
![image](https://github.com/llvm/llvm-project/assets/31106425/e5671978-1c7f-4ab5-88da-826e63f213a6)
This is the register information at the time:
![image](https://github.com/llvm/llvm-project/assets/31106425/90bceddf-029b-460a-8c8e-76a02a367a03)
This is the memory data pointed to by the `x19` register:
![image](https://github.com/llvm/llvm-project/assets/31106425/a4caa711-9257-40f4-9af7-3c051cc5c1f8)
0xffff7c07eff8 is the memory allocated by Alloc.Allocate. It actually allocates 13 bytes. But
0xffff7c07eff8 ~ 0xffff7c07efff is writeable.
0xffff7c07f000 ~ ... is unwriteable.
![image](https://github.com/llvm/llvm-project/assets/31106425/35001dd6-181d-4dc1-8310-760240f9ff1d)
This is a probabilistic question, could it be an memory allocation problem in `Alloc.Allocate`?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vc2O2zYQfhr6MpDAH4mSDj7YcQ3soUDQ7QtQ5FBmIUsuSa3jHPLsBWmvnd2mQXNYQNDfDD_ON_NxRoXghglxTeotqXcrtcTD7NdnNw0ev6762VzWT-DVBG6KMyg4-bkf8Q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