[llvm] [MC][X86] Set SHF_X86_64_LARGE on mergeable constant sections for large code-model (PR #190903)

Farid Zakaria via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 13:59:38 PDT 2026


fzakaria wrote:

> What happens if the same constant is used in small code and large code? Will both versions exist after de-duplication or only large version?

Example with two files sharing the same float constant 3.14f:

```
  // small.c — compiled with default (small) code model
  float small_func(float x) { return x + 3.14f; }

  // large.c — compiled with -mcmodel=large
  float large_func(float x) { return x + 3.14f; }
```

```
  $ clang -c -mcmodel=small -fPIC small.c -o small.o
  $ clang -c -mcmodel=large -fPIC large.c -o large.o
```

The object files place the constant in different sections:
```
  $ readelf -SW small.o | grep rodata
    [4] .rodata.cst4   PROGBITS  ... 000004 04 AM  0 0 4

  $ readelf -SW large.o | grep rodata
    [3] .lrodata.cst4  PROGBITS  ... 000004 04 AMl 0 0 4
```

  After linking, both survive in the output:
```
  $ readelf -SW a.out | grep rodata
    [10] .lrodata  PROGBITS  ... AMl  0 0 4
    [11] .rodata   PROGBITS  ... AM   0 0 4
``
We want this behavior so that small code model can reach the rodata within 2GiB while large code-model goes to the lrodata.


https://github.com/llvm/llvm-project/pull/190903


More information about the llvm-commits mailing list