Mintsuki wrote:

Reproducer for the silent miscompile, with LLVM 22.1.8:

```
$ cat lib.c
double scale(double x, double y) { return x * y + 1.0; }
$ clang --target=loongarch64-unknown-elf -mabi=lp64s -O2 -fPIC -flto -c lib.c
$ ld.lld -shared lib.o -o lib.so
$ llvm-readelf -h lib.so | grep Flags
  Flags:                             0x43, DOUBLE-FLOAT, OBJ-v1
$ llvm-objdump -d --no-show-raw-insn lib.so | grep -A6 "<scale>:"
0000000000010240 <scale>:
   10240:       vldi    $vr2, -912
   10244:       fmadd.d $fa0, $fa0, $fa1, $fa2
   10248:       ret
```

With this patch, `scale` takes its arguments in `$a0`/`$a1` and returns in
`$a0`, as lp64s requires, and the output is marked soft-float:

```
  Flags:                             0x41, SOFT-FLOAT, OBJ-v1
0000000000010240 <scale>:
   10240:       movgr2fr.d      $fa0, $a1
   10244:       movgr2fr.d      $fa1, $a0
   10248:       vldi    $vr2, -912
   1024c:       fmadd.d $fa0, $fa1, $fa0, $fa2
   10250:       movfr2gr.d      $a0, $fa0
   10254:       ret
```

Reproducer for the link error:

```
$ cat a.c
int b(void);
int _start(void) { return b(); }
$ cat b.c
int b(void) { return 0; }
$ clang --target=loongarch64-unknown-elf -mabi=lp64s -flto -c a.c
$ clang --target=loongarch64-unknown-elf -mabi=lp64s -c b.c
$ ld.lld a.o b.o
ld.lld: error: a.out.lto.o: cannot link object files with different ABI from b.o
```

With this patch, the link succeeds and `a.out` is marked soft-float.


https://github.com/llvm/llvm-project/pull/223647
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to