<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63418>63418</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Invalid relocation in ubsan_signals_standalone.cpp on FreeBSD/aarch64
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          VoxSciurorum
      </td>
    </tr>
</table>

<pre>
    My build of llvm main on FreeBSD aarch64 fails:
```
[ 20%] Linking CXX shared library /usr/obj/llvm/llvm-17/lib/clang/17/lib/aarch64-unknown-freebsd13.2/libclang_rt.ubsan_standalone.so
ld: error: CMakeFiles/RTUbsan_standalone.aarch64.dir/ubsan_signals_standalone.cpp.o:(function __ubsan::InitializeDeadlySignals(): .text._ZN7__ubsan23InitializeDeadlySignalsEv+0x78): improper alignment for relocation R_AARCH64_LD64_GOT_LO12_NC: 0x5E73C is not aligned to 8 bytes
```

The problem is apparently this line of assembly:
```
        ldr     x2, [x2, :got_lo12:sigaction]
```
This is an 8 byte load and the relocation expects it to be aligned to 8 bytes.  Earlier in the file I see in the .text segment
```
.set sigaction, __interceptor_trampoline_sigaction
 .globl  __interceptor_trampoline_sigaction
        .type __interceptor_trampoline_sigaction,@function
__interceptor_trampoline_sigaction:
 .cfi_startproc
        b       __interceptor_sigaction
 .cfi_endproc
.Ltmp1: 
        .size __interceptor_trampoline_sigaction, .Ltmp1-__interceptor_trampoline_sigaction 
```
There is no explicit alignment and the function happens to land at an odd multiple of 4 bytes.

Compile the attached file with
```
clang++ --target=aarch64-unknown-freebsd13.2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -O3 -std=c++17 -march=armv8-a -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -S ubsan_signals_standalone.ii
```

[ubsan_signals_standalone.txt](https://github.com/llvm/llvm-project/files/11808461/ubsan_signals_standalone.txt)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVl1v27gS_TX0y4CCRNmy_eAHf9T3BkjbiyZ3t9gXgZJG8jQUKZBUYvfXLygpG7ebdLOCYVLUnDNnhsMP6Rw1GnHDFju2OMxk70_Gbn4z57uSemts384KU102Hy9Q9KQqMDUo9dhCK0mD0XC0iLu7A0hpy1M2h1qScizdsvjA4i3L4uk3vi52IGImFmxxgFvSD6Qb2H_9Cu4kLVagqLDSXoCJY-8sE0dTfGPiGBxODU-WoUcFE8dSSd0wcbwamlTwXj9o86R5bRELVyVpJEabAZNbH_WFkzp3XupKKqMxcmbUqCqWbgGtNTZ09h_lAx5JoWPi-OX-_z_DJo9RRUHvxEqNlspdm5VdF5mQFrGqe116MhryfDAPo-n2RpMnqeg7HlBW6nI3cjCxYmIdhEQezz7K__i0nHAifQPz4ZGJXXxePiOp7azp0IJU1OgWtYfaWLCoTCkHJV_y7fbL_r_ZPL89ZPP8P5_v89vPicg_7QM-Pi8-LNM9kANt_MiCFXgDKyguHt3rcz38358QOmsKhW3Ay66TFrVXF_AncqBIYygp6Ry2hbq8VTgwPaqyQ3sWTOyBLXZTJ902xufKJIKlW0eNHDLMFodX2e6D66BGTxGAMrICqSvwJ7xODJ47LL0D8iHcAl8JPgL4IK0itEB6wNekEG7AIT6PDHMHDpuQ_FclRQ49vAgXe8hz0h5tiZ03NvdWtp0J6cpfrMbURI0yhYL3A6Yn8pcO34MSezaPn6t25HgH6nkmISprCkvB-s6a8kcNxdT-yPe3CAMD6uoFH936tktCcf4Uk6Pv74wJRg7-z8bwRhGhxXFNhDJRVJK_WmHPxfTXaj_JrkPtQuWo8FEGGzBVBW2vPHVqWAjzqaiu19DetF0oqUAnvZflCauxyJ7In14VN22NOyZ2wLmXtkHP0sMvtkfg9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