[llvm] [X86AsmBackend] Check fixup value overflow (PR #176827)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 2 20:57:52 PST 2026


MaskRay wrote:

> Apparently, this is coming from a different part of the code: [coreboot/seabios@`master`/src/pnpbios.c#L70](https://github.com/coreboot/seabios/blob/master/src/pnpbios.c#L70).
> 
> A reduced test case looks like this:
> 
> ```
> $ cat /tmp/q.c
> extern int X;
> 
> unsigned short f(void) { return (unsigned)&X - 0xf0000; }
> 
> $ clang -cc1 -triple i386-grtev4-linux-code16 -Os -emit-obj -mrelocation-model static -fcolor-diagnostics  -o /dev/null q.c
> error: value of -983040 is too large for field of 2 bytes
> 1 error generated.
> ```

Thanks for the example. The integrated assembler matches GNU Assembler. The issue is that `clang -Os -fno-pic` should not generate `leal    X-983040, %eax` in 16-bit mode.

```
% cat q.s
╰─% cat q.s
        .att_syntax
        .code16
        .file   "q.c"
        .text
        .globl  f                               # -- Begin function f
        .type   f, at function
f:                                      # @f
        .cfi_startproc
# %bb.0:                                # %entry
        leal    X-983040, %eax
                                        # kill: def $ax killed $ax killed $eax
        retl
.Lfunc_end0:
        .size   f, .Lfunc_end0-f
        .cfi_endproc
                                        # -- End function

% as --32 q.s
q.s: Assembler messages:
q.s:10: Error: value of fff10000 too large for field of 2 bytes at 00000003
% myllvm-mc -filetype=obj -triple=i386-linux-gnu q.s -o q.o
q.s:10:8: error: value of -983040 is too large for field of 2 bytes
        leal    X-983040, %eax
                 ^
```

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


More information about the llvm-commits mailing list