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

    <tr>
        <th>Summary</th>
        <td>
            Clang generates jump tables in .rodata.cst* instead of custom .rodata.<section> causing EFI runtime failures
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    When compiling U-Boot with Clang, we observed that certain functions marked with a custom section attribute (e.g. .text.efi_runtime) may produce jump tables in a separate .rodata.cst* section. This behavior breaks the expected layout, because the U-Boot linker script only includes .rodata.efi_runtime* but not .rodata.cst*.

This leads to missing jump tables at runtime and ultimately boot failure.

GCC does not show this issue:
GCC emits jump tables into .rodata.efi_runtime.*, which naturally matches the linker script.
Clang emits jump tables into .rodata.cst*, which is excluded by the current linker script.

Reproducer:  [u-boot: psci.c](https://github.com/u-boot/u-boot/blob/master/drivers/firmware/psci.c#L254)
```
unsigned long invoke_psci_fn(unsigned long, unsigned long, unsigned long, unsigned long);

enum efi_reset_type {
  EFI_RESET_COLD = 0,
  EFI_RESET_WARM = 1,
  EFI_RESET_SHUTDOWN = 2,
  EFI_RESET_PLATFORM_SPECIFIC = 3,
};

typedef unsigned long efi_status_t;

__attribute__((__section__(".text.efi_runtime")))
void efi_reset_system(enum efi_reset_type reset_type,
                      efi_status_t reset_status,
                      unsigned long data_size,
                      void *reset_data) {
  if (reset_type == EFI_RESET_COLD ||
      reset_type == EFI_RESET_WARM ||
      reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
    invoke_psci_fn((0x84000000 + 9), 0, 0, 0);
  } else if (reset_type == EFI_RESET_SHUTDOWN) {
    invoke_psci_fn((0x84000000 + 8), 0, 0, 0);
  }
  while (1) ;
}
```
The linker script only collects:  [u-boot: u-boot.lds](https://github.com/u-boot/u-boot/blob/master/arch/arm/cpu/armv8/u-boot.lds#L31)

```
.efi_runtime : {
  __efi_runtime_start = .;
  *(.text.efi_runtime*)
  *(.rodata.efi_runtime*)
  *(.data.efi_runtime*)
  __efi_runtime_stop = .;
}
```
https://godbolt.org/z/nr5qahqsf

Actual behavior (Clang)

- Jump table emitted into .rodata.cst*
- Not captured by .efi_runtime in the linker script

Expected behavior (GCC-compatible)

- Jump table emitted into .rodata.efi_runtime.*
- Automatically included in .efi_runtime section by existing linker script

It seems GCC propagates the custom section naming to associated constant data (such as jump tables), while Clang defaults to placing them into .rodata.cst*.

**Possible solutions:**
Clang to emit jump tables into a section derived from the enclosing function’s custom section (e.g., .rodata.efi_runtime.*).
Or provide an attribute / option to control jump table section placement explicitly.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysV11z4rgS_TXipSuUkSExDzw4BPbm1uzO1Ey25tElyw3WjCx5pDYJ--tvSTYMXze7U7UpKhjU6j59utU6CO_V1iAu2OyRzZ5GoqPaukVlzfabEuaHEmbLR6Wt9ouvNRqQtmmVVmYLf949WkvwqqiGpRZmy_gSXhFs6dHtsAKqBYFER0IZ2HRGkrLGQyPcd6z6fQJk58k24DGugiByquwIgfEMx9sxjAnfaIwbVbjOkGqQ8Tk0Yg-ts1UnEb51TQskSo0elAEBHlvhBCGMna0EibH0xHh-iDGGl1p5KLEWO2UdlA7Fdw9UI-Bbi5KwAi32tqOQUIlSdB7j8pCxVuY7OvDSqZbAGr0HZaTuKvTHkGd4cyg7AmPpAtGYJTlL8ghHo6g8kIVGeR_oPU1LEAzOQJgKOk2qEYR6D2UAtBFKdw4Hd78tl1BZ9DGgr-0rUAigvO-QpQcLbBT5C-7I3sI_ZjyPpa2VrMEI6pzQeg-NIFljT9wZJQFHbIi_C9Kz8NO38oBvkcgKyn10LDvn0NB1AJbkn3FoAcfSHIDNHru7wEf41HqpxpLNnhjPaqLWh8z5mvH1VlHdlWNpG8bXw4aTh1LbkvF1IzyhY3xdObVD5xlf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