llvm / llvm/llvm-project

[compiler-rt] ppc/fixunstfti ldUnion size mismatch when building against musl, uninitialised memory read

Open
#159,789 0 comments 0 reactions 0 assignees View on GitHub
compiler-rt:builtins
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://github.com/llvm/llvm-project/blob/50ef746a12a77e2e9f0c61f3ad92dfe0d8019194/compiler-rt/lib/builtins/ppc/fixunstfti.c#L7-L12

When building against musl on POWER (64-bit big-endian is what I'm using), musl makes `long double` 64-bit wide.

From musl's `INSTALL`:
```
Supported Targets
-----------------

musl can be built for the following CPU instruction set architecture
and ABI combinations:

[...]

* PowerPC
* Compiler toolchain must provide 64-bit long double, not IBM
double-double or IEEE quad
[...]

* PowerPC64
[...]
* Compiler toolchain must provide 64-bit long double, not IBM
double-double or IEEE quad
```

So this union has members of different lengths (64-bit, 128-bit, 128-bit):

https://github.com/llvm/llvm-project/blob/50ef746a12a77e2e9f0c61f3ad92dfe0d8019194/compiler-rt/lib/builtins/ppc/fixunstfti.c#L28-L34

And the `ldUnion.ull[1]` read after a `ldUnion.ld` write here:

https://github.com/llvm/llvm-project/blob/50ef746a12a77e2e9f0c61f3ad92dfe0d8019194/compiler-rt/lib/builtins/ppc/fixunstfti.c#L41-L47

…ends up reading from uninitialised memory, as pointed out by the compiler:

```
[10/163] Building C object lib/builtins/CMakeFiles/clang_rt.builtins-powerpc64.dir/ppc/fixunstfti.c.o
FAILED: [code=1] lib/builtins/CMakeFiles/clang_rt.builtins-powerpc64.dir/ppc/fixunstfti.c.o
/nix/store/is7m521kwczmr6ji3fi75qw7pl6qdz7h-powerpc64-unknown-linux-musl-gcc-wrapper-14.3.0/bin/powerpc64-unknown-linux-musl-gcc -DVISIBILITY_HIDDEN -I/build/compiler-rt-src-22.0.0-unstable-2025-09-07/compiler-rt/lib/builtins/../../../third-party/siphash/include -Wall -Wno>
cc1: warning: command-line option '-nostdinc++' is valid for C++/ObjC++ but not for C
/build/compiler-rt-src-22.0.0-unstable-2025-09-07/compiler-rt/lib/builtins/ppc/fixunstfti.c: In function '__fixunstfti':
/build/compiler-rt-src-22.0.0-unstable-2025-09-07/compiler-rt/lib/builtins/ppc/fixunstfti.c:47:57: error: 'ldUnion.ull[1]' may be used uninitialized [-Werror=maybe-uninitialized]
47 | loExponent = ((ldUnion.ull[1] & 0x7FFFFFFFFFFFFFFFll) >> 52) - BIAS;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/build/compiler-rt-src-22.0.0-unstable-2025-09-07/compiler-rt/lib/builtins/ppc/fixunstfti.c:34:5: note: 'ldUnion.ull[1]' was declared here
34 | } ldUnion;
| ^~~~~~~
cc1: some warnings being treated as errors
```

Contributor guide

Open the contributing guide

Research direction

Read compiler-rt/lib/builtins/ppc/fixunstfti.c at lines 7-12, 28-34, and 41-47, then reproduce the compiler-rt build against musl on 64-bit big-endian POWER using the reported configuration. Done means the affected build no longer reports a possible uninitialized read and the builtin remains correct for the supported long-double layouts.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.