[Bug ld/23428] ld does not put program headers in a code-only load segment

2018-08-11 Thread nsz at port70 dot net
https://sourceware.org/bugzilla/show_bug.cgi?id=23428

--- Comment #14 from nsz at port70 dot net ---
> @Szabolcs: If you rebuild gcc-8 on Debian testing with "--enable-cet=auto"
> added to CONFARGS in debian/rules2, then you should be able to reproduce the
> musl-gcc crash (after removing the --build-id workaround from 
> musl-gcc.specs!).
> 
> (It appears that "--enable-cet=auto" is the important difference between 
> Arch's
> and Debian's GCC packages.)

thanks, i could reproduce the issue:

it seems ld tries to add a dummy .note.gnu.property to force the
program headers into a load segment, but if there is already a
.note.gnu.property in some of the input object files then it just
tries to merge those and don't add a dummy note at all, however
the merging rules may produce an empty note in the end and then
the note section is dropped.

# cat i.c
int i;
# gcc -fcf-protection=full -c i.c
# readelf -n i.o

Displaying notes found in: .note.gnu.property
  Owner Data size   Description
  GNU  0x0010   NT_GNU_PROPERTY_TYPE_0
  Properties: x86 feature: IBT, SHSTK
# cat t.s
.globl _start
_start:
  ret
# gcc -c t.s
# ld t.o
# readelf -ln a.out

Elf file type is EXEC (Executable file)
Entry point 0x401000
There are 3 program headers, starting at offset 64

Program Headers:
  Type   Offset VirtAddr   PhysAddr
 FileSizMemSiz  Flags  Align
  LOAD   0x 0x0040 0x0040
 0x0108 0x0108  R  0x1000
  LOAD   0x1000 0x00401000 0x00401000
 0x0001 0x0001  R E0x1000
  NOTE   0x00e8 0x004000e8 0x004000e8
 0x0020 0x0020  R  0x8

 Section to Segment mapping:
  Segment Sections...
   00 .note.gnu.property 
   01 .text 
   02 .note.gnu.property 

Displaying notes found in: .note.gnu.property
  Owner Data size   Description
  GNU  0x0010   NT_GNU_PROPERTY_TYPE_0
  Properties: x86 ISA used: i486
# ld t.o i.o
# readelf -ln a.out

Elf file type is EXEC (Executable file)
Entry point 0x401000
There are 3 program headers, starting at offset 64

Program Headers:
  Type   Offset VirtAddr   PhysAddr
 FileSizMemSiz  Flags  Align
  LOAD   0x1000 0x00401000 0x00401000
 0x0001 0x0001  R E0x1000
  LOAD   0x2000 0x00402000 0x00402000
 0x 0x0008  RW 0x1000
  GNU_STACK  0x 0x 0x
 0x 0x  RWE0x10

 Section to Segment mapping:
  Segment Sections...
   00 .text 
   01 .bss 
   02

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/23428] ld does not put program headers in a code-only load segment

2018-08-11 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=23428

--- Comment #15 from H.J. Lu  ---
(In reply to nsz from comment #14)
> > @Szabolcs: If you rebuild gcc-8 on Debian testing with "--enable-cet=auto"
> > added to CONFARGS in debian/rules2, then you should be able to reproduce the
> > musl-gcc crash (after removing the --build-id workaround from 
> > musl-gcc.specs!).
> > 
> > (It appears that "--enable-cet=auto" is the important difference between 
> > Arch's
> > and Debian's GCC packages.)
> 
> thanks, i could reproduce the issue:
> 
> it seems ld tries to add a dummy .note.gnu.property to force the
> program headers into a load segment, but if there is already a
> .note.gnu.property in some of the input object files then it just
> tries to merge those and don't add a dummy note at all, however
> the merging rules may produce an empty note in the end and then
> the note section is dropped.

Please try binutils master branch with

commit f7309df20c4e787041cedc4a6aced89c15259e54
Author: H.J. Lu 
Date:   Wed Aug 8 06:09:15 2018 -0700

x86: Properly merge GNU_PROPERTY_X86_ISA_1_USED

Without the GNU_PROPERTY_X86_ISA_1_USED property, all ISAs may be used.
If a bit in the GNU_PROPERTY_X86_ISA_1_USED property is unset, the
corresponding x86 instruction set isn\u2019t used.  When merging properties
from 2 input files and one input file doesn't have the
GNU_PROPERTY_X86_ISA_1_USED property, the output file shouldn't have
it neither.  This patch removes the GNU_PROPERTY_X86_ISA_1_USED
property if an input file doesn't have it.

This patch replaces the GNU_PROPERTY_X86_ISA_1_USED property with the
GNU_PROPERTY_X86_ISA_1_NEEDED property which is the minimum ISA
requirement.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/23428] ld does not put program headers in a code-only load segment

2018-08-11 Thread evangelos at foutrelis dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=23428

--- Comment #16 from Evangelos Foutras  ---
The test case from comment #14 is still reproducible for me with both binutils
master (1dc9e2d6) and binutils-2_31-branch (6ee91b1e). No change at all in the
resulting binary, compared to just the patch from comment #4.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/23428] ld does not put program headers in a code-only load segment

2018-08-11 Thread cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23428

--- Comment #17 from cvs-commit at gcc dot gnu.org  ---
The master branch has been updated by H.J. Lu :

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

commit ab9e342807d132182892de1be1a92d6e91a5c1da
Author: H.J. Lu 
Date:   Sat Aug 11 06:41:33 2018 -0700

x86: Properly add X86_ISA_1_NEEDED property

Existing properties may be removed during property merging.  We avoid
adding X86_ISA_1_NEEDED property only if existing properties won't be
removed.

bfd/

PR ld/23428
* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Don't
add X86_ISA_1_NEEDED property only if existing properties won't
be removed.

ld/

PR ld/23428
* testsuite/ld-elf/dummy.s: New file.
* testsuite/ld-elf/linux-x86.S: Add X86_FEATURE_1_AND property.
* testsuite/ld-elf/linux-x86.exp: Add dummy.s to pr23428.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/23428] ld does not put program headers in a code-only load segment

2018-08-11 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=23428

--- Comment #18 from H.J. Lu  ---
(In reply to Evangelos Foutras from comment #16)
> The test case from comment #14 is still reproducible for me with both
> binutils master (1dc9e2d6) and binutils-2_31-branch (6ee91b1e). No change at
> all in the resulting binary, compared to just the patch from comment #4.

Please try master branch again.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/23428] ld does not put program headers in a code-only load segment

2018-08-11 Thread evangelos at foutrelis dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=23428

--- Comment #19 from Evangelos Foutras  ---
(In reply to H.J. Lu from comment #18)
> (In reply to Evangelos Foutras from comment #16)
> > The test case from comment #14 is still reproducible for me with both
> > binutils master (1dc9e2d6) and binutils-2_31-branch (6ee91b1e). No change at
> > all in the resulting binary, compared to just the patch from comment #4.
> 
> Please try master branch again.

Your latest commit fixes the issue I was experiencing. Thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/23515] New: Empty GNU_PROPERTY_X86_FEATURE_1_AND isn't removed

2018-08-11 Thread hjl.tools at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=23515

Bug ID: 23515
   Summary: Empty GNU_PROPERTY_X86_FEATURE_1_AND isn't removed
   Product: binutils
   Version: 2.32 (HEAD)
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: hjl.tools at gmail dot com
  Target Milestone: ---
Target: i386,x86-64

[hjl@gnu-tools-1 tmp]$ cat x.s
.section ".note.gnu.property", "a"
.p2align 2
.long 1f - 0f   /* name length */
.long 5f - 2f   /* data length */
.long 5 /* note type */
0:  .asciz "GNU"/* vendor name */
1:
.p2align 2
2:  .long 0xc002/* pr_type.  */
.long 4f - 3f   /* pr_datasz.  */
3:
.long 0x0
4:
.p2align 2
5:
[hjl@gnu-tools-1 tmp]$ gcc -c -m32 x.s
[hjl@gnu-tools-1 tmp]$ ld -shared -m elf_i386 x.o
[hjl@gnu-tools-1 tmp]$ readelf -n x.o

Displaying notes found in: .note.gnu.property
  Owner Data size   Description
  GNU  0x000c   NT_GNU_PROPERTY_TYPE_0
  Properties: x86 feature: 
[hjl@gnu-tools-1 tmp]$

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils