https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117992

Feiyang Huang <220255623 at seu dot edu.cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |220255623 at seu dot edu.cn

--- Comment #14 from Feiyang Huang <220255623 at seu dot edu.cn> ---
This report covers the same `avoid_linker_hardening_p` root cause as
PR 117992. The existing description focuses on the warning produced by
explicit `-pie`; below is a focused end-to-end observation for the
`-no-pie` case that was discussed in the comments.

With an upstream-source GCC 15.2.0 configured for
`x86_64-pc-linux-gnu --enable-default-pie`:

    int main(void) { return 0; }

    $ gcc -O2 -Wall -Wextra -fhardened -no-pie trigger.c -o hardened-no-pie
    gcc: warning: linker hardening options not enabled by '-fhardened' because
other link options were specified on the command line
    $ readelf -l hardened-no-pie | grep GNU_RELRO
      GNU_RELRO      0x0000000000002e28 0x0000000000403e28 0x0000000000403e28
    $ readelf -d hardened-no-pie | grep -E 'BIND_NOW|FLAGS_1.*NOW'
    (no output)

The command exits 0. The resulting ELF has `GNU_RELRO`, but no
`BIND_NOW` tag and no `FLAGS_1 NOW` bit. `-fhardened` alone produces
both. Adding `-Wl,-z,now` explicitly also restores `BIND_NOW`.

The final `-###` collect2 command for the failing case contains neither
`-z now` nor `-z relro` on this build. This is consistent with the
comments saying that explicit PIE mode should not suppress the
independent linker-hardening arguments.

I also reproduced the same missing BIND_NOW result with GCC 16.1.0 and
released GCC 16.2.0. A minimal reproducer and the GCC 15.2.0 evidence
are available as one small text-only archive.

Reply via email to