public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored
@ 2021-12-08 23:51 hjl.tools at gmail dot com
  2021-12-09  1:11 ` [Bug dynamic-link/28676] " hjl.tools at gmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2021-12-08 23:51 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

            Bug ID: 28676
           Summary: p_align on PT_LOAD segment in DSO isn't honored
           Product: glibc
           Version: 2.35
            Status: NEW
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: hjl.tools at gmail dot com
  Target Milestone: ---

Created attachment 13838
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13838&action=edit
A testcase

[hjl@gnu-cfl-2 aligned-1]$ make 
gcc -pie -fPIE -Wl,-z,max-page-size=0x200000 -O2 -o pie main.c load.c
gcc -no-pie -Wl,-z,max-page-size=0x200000 -O2 -o pde main.c load.c
gcc -O2 -fPIC   -c -o load.o load.c
gcc -shared -Wl,-z,max-page-size=0x200000 -o libload.so load.o
gcc -no-pie -Wl,-z,max-page-size=0x200000 -O2 -o dso main.c libload.so -Wl,-R,.
./pde
foo: 0xe00000
./pie
foo: 0x55ea36a00000
./dso
foo: 0x7fafe6308000
make: *** [Makefile:8: all] Aborted (core dumped)
[hjl@gnu-cfl-2 aligned-1]$ 

Kernel loader honors 2MB p_align in PIE.  But ld.so doesn't honor 2MB p_align
in DSO.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
@ 2021-12-09  1:11 ` hjl.tools at gmail dot com
  2021-12-10 19:45 ` hjl.tools at gmail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2021-12-09  1:11 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://bugzilla.kernel.org
                   |                            |/show_bug.cgi?id=215275

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
I also opened a kernel bug:

https://bugzilla.kernel.org/show_bug.cgi?id=215275

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
  2021-12-09  1:11 ` [Bug dynamic-link/28676] " hjl.tools at gmail dot com
@ 2021-12-10 19:45 ` hjl.tools at gmail dot com
  2021-12-13 15:00 ` fweimer at redhat dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2021-12-10 19:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |2.35

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed by

commit 718fdd87b1b98ef88e883a37d9c18867256fa5a4
Author: Rongwei Wang <rongwei.wang@linux.alibaba.com>
Date:   Fri Dec 10 20:39:10 2021 +0800

    elf: Properly align PT_LOAD segments [BZ #28676]

    When PT_LOAD segment alignment > the page size, allocate enough space to
    ensure that the segment can be properly aligned.  This change helps code
    segments use huge pages become simple and available.

    This fixes [BZ #28676].

    Signed-off-by: Xu Yu <xuyu@linux.alibaba.com>
    Signed-off-by: Rongwei Wang <rongwei.wang@linux.alibaba.com>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
  2021-12-09  1:11 ` [Bug dynamic-link/28676] " hjl.tools at gmail dot com
  2021-12-10 19:45 ` hjl.tools at gmail dot com
@ 2021-12-13 15:00 ` fweimer at redhat dot com
  2021-12-13 15:00 ` fweimer at redhat dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fweimer at redhat dot com @ 2021-12-13 15:00 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=28688

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2021-12-13 15:00 ` fweimer at redhat dot com
@ 2021-12-13 15:00 ` fweimer at redhat dot com
  2021-12-13 15:02 ` fweimer at redhat dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fweimer at redhat dot com @ 2021-12-13 15:00 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=28689

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (3 preceding siblings ...)
  2021-12-13 15:00 ` fweimer at redhat dot com
@ 2021-12-13 15:02 ` fweimer at redhat dot com
  2021-12-13 23:36 ` sam at gentoo dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: fweimer at redhat dot com @ 2021-12-13 15:02 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (4 preceding siblings ...)
  2021-12-13 15:02 ` fweimer at redhat dot com
@ 2021-12-13 23:36 ` sam at gentoo dot org
  2021-12-14  5:31 ` i at maskray dot me
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: sam at gentoo dot org @ 2021-12-13 23:36 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (5 preceding siblings ...)
  2021-12-13 23:36 ` sam at gentoo dot org
@ 2021-12-14  5:31 ` i at maskray dot me
  2021-12-15 22:25 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: i at maskray dot me @ 2021-12-14  5:31 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

Fangrui Song <i at maskray dot me> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |i at maskray dot me

--- Comment #3 from Fangrui Song <i at maskray dot me> ---
This is not a bug per se. My reasoning is at
https://sourceware.org/pipermail/libc-alpha/2021-December/134121.html 

`__attribute__((aligned(0x200000))) = 1;` does not necessarily mean the large
alignment needs to be satisfied on a system with a smaller page size.
Now "elf: Properly align PT_LOAD segments [BZ #28676]" overaligns memory
mappings to p_align to make the use case work. It's a new feature, not a
bugfix.

The 2020 kernel commit
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ce81bb256a224259ab686742a6284930cbe4f1fa
has no waste, so it is more justifiable.
The emulation in ld.so, however, would incur significant overhead, so it needs
more thoughts.
At the very least, the max-page-size=0x200000 for -z noseparate-code on x86-64
may be problematic.
It looks like we need more thoughts how tools like objcopy and ld can make the
cost small, or whether such changes are justifiable.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (6 preceding siblings ...)
  2021-12-14  5:31 ` i at maskray dot me
@ 2021-12-15 22:25 ` hjl.tools at gmail dot com
  2022-01-05 13:32 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2021-12-15 22:25 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> ---
Linker may set p_align of a PT_LOAD segment larger than p_align of the
first PT_LOAD segment to satisfy a section alignment:

Elf file type is DYN (Shared object file)
Entry point 0x0
There are 10 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000834 0x0000000000000834  R E    0x1000
  LOAD           0x0000000000000e00 0x0000000000001e00 0x0000000000001e00
                 0x0000000000000230 0x0000000000000230  RW     0x1000
  LOAD           0x0000000000400000 0x0000000000400000 0x0000000000400000
                 0x0000000000000004 0x0000000000000008  RW     0x400000
...

 Section to Segment mapping:
  Segment Sections...
   00     .note.gnu.property .note.gnu.build-id .gnu.hash .dynsym .dynstr
.gnu.v
ersion .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini
.rodat
a .eh_frame_hdr .eh_frame
   01     .init_array .fini_array .data.rel.ro .dynamic .got .got.plt
   02     .data .bss

We should align the first PT_LOAD segment to the maximum p_align of all
PT_LOAD segments, similar to the kernel commit:

commit ce81bb256a224259ab686742a6284930cbe4f1fa
Author: Chris Kennelly <ckennelly@google.com>
Date:   Thu Oct 15 20:12:32 2020 -0700

    fs/binfmt_elf: use PT_LOAD p_align values for suitable start address

A patch with a testcase is posted at

https://sourceware.org/pipermail/libc-alpha/2021-December/134219.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (7 preceding siblings ...)
  2021-12-15 22:25 ` hjl.tools at gmail dot com
@ 2022-01-05 13:32 ` hjl.tools at gmail dot com
  2022-01-05 13:32 ` hjl.tools at gmail dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2022-01-05 13:32 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=28695

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (8 preceding siblings ...)
  2022-01-05 13:32 ` hjl.tools at gmail dot com
@ 2022-01-05 13:32 ` hjl.tools at gmail dot com
  2022-01-21 19:43 ` cvs-commit at gcc dot gnu.org
  2022-01-24 14:52 ` hjl.tools at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2022-01-05 13:32 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |NEW

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (9 preceding siblings ...)
  2022-01-05 13:32 ` hjl.tools at gmail dot com
@ 2022-01-21 19:43 ` cvs-commit at gcc dot gnu.org
  2022-01-24 14:52 ` hjl.tools at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-21 19:43 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

--- Comment #5 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e22a4557eb39d7cba9a74d70f4582c13f1a7a83a

commit e22a4557eb39d7cba9a74d70f4582c13f1a7a83a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Dec 15 13:58:33 2021 -0800

    elf: Properly align all PT_LOAD segments [BZ #28676]

    Linker may set p_align of a PT_LOAD segment larger than p_align of the
    first PT_LOAD segment to satisfy a section alignment:

    Elf file type is DYN (Shared object file)
    Entry point 0x0
    There are 10 program headers, starting at offset 64

    Program Headers:
      Type           Offset             VirtAddr           PhysAddr
                     FileSiz            MemSiz              Flags  Align
      LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                     0x0000000000000834 0x0000000000000834  R E    0x1000
      LOAD           0x0000000000000e00 0x0000000000001e00 0x0000000000001e00
                     0x0000000000000230 0x0000000000000230  RW     0x1000
      LOAD           0x0000000000400000 0x0000000000400000 0x0000000000400000
                     0x0000000000000004 0x0000000000000008  RW     0x400000
    ...

     Section to Segment mapping:
      Segment Sections...
       00     .note.gnu.property .note.gnu.build-id .gnu.hash .dynsym .dynstr
.gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini
.rodata .eh_frame_hdr .eh_frame
       01     .init_array .fini_array .data.rel.ro .dynamic .got .got.plt
       02     .data .bss

    We should align the first PT_LOAD segment to the maximum p_align of all
    PT_LOAD segments, similar to the kernel commit:

    commit ce81bb256a224259ab686742a6284930cbe4f1fa
    Author: Chris Kennelly <ckennelly@google.com>
    Date:   Thu Oct 15 20:12:32 2020 -0700

        fs/binfmt_elf: use PT_LOAD p_align values for suitable start address

    This fixes BZ #28676.

    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug dynamic-link/28676] p_align on PT_LOAD segment in DSO isn't honored
  2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
                   ` (10 preceding siblings ...)
  2022-01-21 19:43 ` cvs-commit at gcc dot gnu.org
@ 2022-01-24 14:52 ` hjl.tools at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: hjl.tools at gmail dot com @ 2022-01-24 14:52 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28676

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-01-24 14:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08 23:51 [Bug dynamic-link/28676] New: p_align on PT_LOAD segment in DSO isn't honored hjl.tools at gmail dot com
2021-12-09  1:11 ` [Bug dynamic-link/28676] " hjl.tools at gmail dot com
2021-12-10 19:45 ` hjl.tools at gmail dot com
2021-12-13 15:00 ` fweimer at redhat dot com
2021-12-13 15:00 ` fweimer at redhat dot com
2021-12-13 15:02 ` fweimer at redhat dot com
2021-12-13 23:36 ` sam at gentoo dot org
2021-12-14  5:31 ` i at maskray dot me
2021-12-15 22:25 ` hjl.tools at gmail dot com
2022-01-05 13:32 ` hjl.tools at gmail dot com
2022-01-05 13:32 ` hjl.tools at gmail dot com
2022-01-21 19:43 ` cvs-commit at gcc dot gnu.org
2022-01-24 14:52 ` hjl.tools at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).