Bug 28819

Summary: [2.38 Regression] ld between Jan 06 and Jan 21 builds binaries without RELRO
Product: binutils Reporter: Matthias Klose <doko>
Component: ldAssignee: H.J. Lu <hjl.tools>
Status: RESOLVED FIXED    
Severity: critical CC: amodra, hjl.tools
Priority: P2    
Version: 2.38   
Target Milestone: 2.38   
Host: Target:
Build: Last reconfirmed:
Attachments: A patch

Description Matthias Klose 2022-01-25 12:03:06 UTC
last known ld was 20220106, first known broken one 20220119.

ld builds binaries without RELRO on at least amd64, i386, ppc64 and s390x.

reproducer in https://bugs.debian.org/1004272
https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=1004272;filename=bug1004272-glibc.tar.gz;msg=10
Comment 1 H.J. Lu 2022-01-25 14:49:13 UTC
Created attachment 13927 [details]
A patch

Try this.
Comment 2 Matthias Klose 2022-01-26 08:27:45 UTC
this works at least on i686 and s390x.
Comment 3 Sourceware Commits 2022-01-26 13:32:29 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c804c6f98d342c3d46f73d7a7ec6229d5ab1c9f3

commit c804c6f98d342c3d46f73d7a7ec6229d5ab1c9f3
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Jan 14 13:48:36 2022 -0800

    ld: Rewrite lang_size_relro_segment_1
    
    1. Compute the desired PT_GNU_RELRO segment base and find the maximum
    section alignment of sections starting from the PT_GNU_RELRO segment.
    2. Find the first preceding load section.
    3. Don't add the 1-page gap between the first preceding load section and
    the relro segment if the maximum page size >= the maximum section
    alignment.  Align the PT_GNU_RELRO segment first.  Subtract the maximum
    page size if therer is still a 1-page gap.
    
            PR ld/28743
            PR ld/28819
            * ldlang.c (lang_size_relro_segment_1): Rewrite.
            * testsuite/ld-x86-64/pr28743-1.d: New file.
            * testsuite/ld-x86-64/pr28743-1.s: Likewise.
            * testsuite/ld-x86-64/x86-64.exp: Run pr28743-1.
Comment 4 Sourceware Commits 2022-01-26 13:47:13 UTC
The binutils-2_38-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8b7c6a1fbab5b0efc6abb50cdb24aef3954ac018

commit 8b7c6a1fbab5b0efc6abb50cdb24aef3954ac018
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Jan 14 13:48:36 2022 -0800

    ld: Rewrite lang_size_relro_segment_1
    
    1. Compute the desired PT_GNU_RELRO segment base and find the maximum
    section alignment of sections starting from the PT_GNU_RELRO segment.
    2. Find the first preceding load section.
    3. Don't add the 1-page gap between the first preceding load section and
    the relro segment if the maximum page size >= the maximum section
    alignment.  Align the PT_GNU_RELRO segment first.  Subtract the maximum
    page size if therer is still a 1-page gap.
    
            PR ld/28743
            PR ld/28819
            * ldlang.c (lang_size_relro_segment_1): Rewrite.
            * testsuite/ld-x86-64/pr28743-1.d: New file.
            * testsuite/ld-x86-64/pr28743-1.s: Likewise.
            * testsuite/ld-x86-64/x86-64.exp: Run pr28743-1.
    
    (cherry picked from commit c804c6f98d342c3d46f73d7a7ec6229d5ab1c9f3)
Comment 5 H.J. Lu 2022-01-26 13:48:07 UTC
Fixed for 2.38.
Comment 6 Sourceware Commits 2022-02-07 03:13:50 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5197c88e2a8a17f7a67ce683df068b5bdf619427

commit 5197c88e2a8a17f7a67ce683df068b5bdf619427
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Feb 5 20:01:40 2022 +1030

    Revert "ld: Rewrite lang_size_relro_segment_1"
    
    This reverts commit c804c6f98d342c3d46f73d7a7ec6229d5ab1c9f3.
    
            PR ld/28743
            PR ld/28819
            * ldlang.c (lang_size_relro_segment_1): Revert 2022-01-14 change.
            * testsuite/ld-x86-64/pr28743-1.d: Likewise.
            * testsuite/ld-x86-64/pr28743-1.s: Likewise.
            * testsuite/ld-x86-64/x86-64.exp: Likewise.
Comment 7 Sourceware Commits 2022-02-07 03:14:00 UTC
The binutils-2_38-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fb42d68c3d694a2e2344d9ae65444e6cc761cb4f

commit fb42d68c3d694a2e2344d9ae65444e6cc761cb4f
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Feb 7 09:37:51 2022 +1030

    Revert "ld: Rewrite lang_size_relro_segment_1"
    
    This reverts commit 8b7c6a1fbab5b0efc6abb50cdb24aef3954ac018.
    
            PR ld/28743
            PR ld/28819
            * ldlang.c (lang_size_relro_segment_1): Revert 2022-01-14 change.
            testsuite/ld-x86-64/pr28743-1.d: Likewise.
            testsuite/ld-x86-64/pr28743-1.s: Likewise.
            testsuite/ld-x86-64/x86-64.exp: Likewise.