Bug 125869 - [17 regression] binutils pr25754-1ba FAILs
Summary: [17 regression] binutils pr25754-1ba FAILs
Status: RESOLVED MOVED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 17.0
: P3 normal
Target Milestone: 17.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2026-06-18 03:35 UTC by Sam James
Modified: 2026-06-18 05:56 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
pr25754-1a.c (172 bytes, text/plain)
2026-06-18 03:35 UTC, Sam James
Details
pr25754-1b.s (40 bytes, text/plain)
2026-06-18 03:36 UTC, Sam James
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2026-06-18 03:35:52 UTC
Created attachment 64764 [details]
pr25754-1a.c

With GCC trunk, two binutils ld tests fail:
```
$ grep ^FAIL ld.log
FAIL: Run pr25754-1aa (-no-pie -fno-PIE -w)
FAIL: Run pr25754-1ba (-no-pie -fPIE -w)
```

test.sh:
```
#!/bin/bash
set -x

gcc -O3 -fno-PIE pr25754-1a.c -o pr25754-1a.o -c
gcc -fno-PIE pr25754-1b.s -o pr25754-1b.o -c
gcc -no-pie  -z noexecstack pr25754-1a.o pr25754-1b.o -o pr25754-1ba
./pr25754-1ba &> x.txt

grep -q "PASS" x.txt && exit 0

exit 1
```

It works with -O0.
Comment 1 Sam James 2026-06-18 03:36:06 UTC
Created attachment 64765 [details]
pr25754-1b.s
Comment 2 Sam James 2026-06-18 03:37:37 UTC
If I add:
  else
    __builtin_printf("p=%p\n", get_bar());

```
$ ./a.sh || cat x.txt
+ gcc -O3 -fno-PIE pr25754-1a.c -o pr25754-1a.o -c
+ gcc -fno-PIE pr25754-1b.s -o pr25754-1b.o -c
+ gcc -no-pie -z noexecstack pr25754-1a.o pr25754-1b.o -o pr25754-1ba
+ ./pr25754-1ba
+ grep -q PASS x.txt
+ exit 1
p=0x2a
```

It works at -O0.
Comment 3 Sam James 2026-06-18 03:46:49 UTC
Interestingly, its siblings pass with e.g. 0xfffffff0U in pr25754-2a.c.
Comment 4 Sam James 2026-06-18 04:11:57 UTC
This one is standalone and it fails too:
```
#include <stdint.h>

uintptr_t bar;

uintptr_t *
__attribute__ ((noinline, noclone))
get_bar (void)
{
  return &bar;
}

int
main ()
{
  if ((uintptr_t) get_bar () != 42)
    __builtin_abort();
  return 0;
}
```

I don't think the optimisation is valid for this variant unless -fno-semantic-interposition is used, because an interposed get_bar could return a pointer to some malloc'd memory that has 42?
Comment 5 Sam James 2026-06-18 04:13:26 UTC
(In reply to Sam James from comment #4)
> This one is standalone and it fails too:
> ...
> I don't think the optimisation is valid for this variant unless
> -fno-semantic-interposition is used, because an interposed get_bar could
> return a pointer to some malloc'd memory that has 42?

With trunk, it unconditionally calls abort; in 16, it doesn't.
Comment 6 Drea Pinski 2026-06-18 04:17:16 UTC
Most likely `&a` is thought not to be a null pointer and 42 is in the same "page" as the zero page ...
Comment 7 Drea Pinski 2026-06-18 04:22:01 UTC
(In reply to Drea Pinski from comment #6)
> Most likely `&a` is thought not to be a null pointer and 42 is in the same
> "page" as the zero page ...

s/a/bar/ but the generic idea stands.
Comment 8 H.J. Lu 2026-06-18 04:47:59 UTC
(In reply to Drea Pinski from comment #6)
> Most likely `&a` is thought not to be a null pointer and 42 is in the same
> "page" as the zero page ...

800 seems a magic number.  Below it, get_bar call is optimized out.
Comment 9 Sam James 2026-06-18 04:49:50 UTC
--param min-pagesize (ok, meant to only be for warnings) and -fno-delete-null-pointer-checks (supposed to say if you can have a pointer at 0 as well for some targets) don't make a difference.
Comment 10 Drea Pinski 2026-06-18 04:58:49 UTC
Note 42 is not aligned.
Switching to 40 works.
Comment 11 Drea Pinski 2026-06-18 05:03:20 UTC
Basically I think the issue is the testcase.
Adding noipa also allows it to work.
Comment 12 Drea Pinski 2026-06-18 05:04:04 UTC
Even fails with clang.
Comment 13 Sam James 2026-06-18 05:18:54 UTC
(In reply to Drea Pinski from comment #10)
> Note 42 is not aligned.
> Switching to 40 works.

Oh.
Comment 14 Richard Biener 2026-06-18 05:56:27 UTC
I think the testcase is bogus, move back to binutils.