[PATCH] x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed

H.J. Lu hjl.tools@gmail.com
Fri Jul 20 16:41:00 GMT 2018


On Thu, Jul 19, 2018 at 2:33 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> On Thu, Jul 19, 2018 at 10:36:43AM -0700, H.J. Lu wrote:
>> When -z separate-code, which is enabled by default for Linux/x86, is
>> used to create executable, ld won't place any data in the code-only
>> PT_LOAD segment.  If there are no data sections placed before the
>> code-only PT_LOAD segment, the program headers won't be mapped into
>> any PT_LOAD segment.  When the executable tries to access it (based
>> on the program header address passed in AT_PHDR), it will lead to
>> segfault.  This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if
>> there may be no data sections before the text section so that the
>> first PT_LOAD segment won't be code-only and will contain the program
>> header.
>>
>
> Here is the updated patch.  Any comments?
>
>
> H.J.
> --
> When -z separate-code, which is enabled by default for Linux/x86, is
> used to create executable, ld won't place any data in the code-only
> PT_LOAD segment.  If there are no data sections placed before the
> code-only PT_LOAD segment, the program headers won't be mapped into
> any PT_LOAD segment.  When the executable tries to access it (based
> on the program header address passed in AT_PHDR), it will lead to
> segfault.  This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if
> there may be no data sections before the text section so that the
> first PT_LOAD segment won't be code-only and will contain the program
> header.
>
> Testcases are adjusted to either pass "-z noseparate-code" to ld or
> discard the .note.gnu.property section.  A Linux/x86 run-time test is
> added.
>
> bfd/
>
>         PR ld/23428
>         * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the
>         separate code program header is needed, make sure that the first
>         read-only PT_LOAD segment has no code by adding a
>         GNU_PROPERTY_X86_ISA_1_USED note.
>
> ld/
>
>         PR ld/23428
>         * testsuite/ld-elf/linux-x86-start.S: New file.
>         * testsuite/ld-elf/linux-x86-syscall.S: Likewise.
>         * testsuite/ld-elf/linux-x86.exp: Likewise.
>         * testsuite/ld-elf/pr23428.c: Likewise.
>         * testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld
>         for Linux/x86 targets.
>         * testsuite/ld-i386/abs-iamcu.d: Likewise.
>         * testsuite/ld-i386/abs.d: Likewise.
>         * testsuite/ld-i386/pr12718.d: Likewise.
>         * testsuite/ld-i386/pr12921.d: Likewise.
>         * testsuite/ld-x86-64/abs-k1om.d: Likewise.
>         * testsuite/ld-x86-64/abs-l1om.d: Likewise.
>         * testsuite/ld-x86-64/abs.d: Likewise.
>         * testsuite/ld-x86-64/pr12718.d: Likewise.
>         * testsuite/ld-x86-64/pr12921.d: Likewise.
>         * testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property
>         section.
>         * testsuite/ld-scripts/print-memory-usage.t: Likewise.
>         * testsuite/ld-scripts/size-2.t: Likewise.
>         * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld
>         to create executable if language is "asm".


This is the patch I am checking into master branch.  I will backport it
to 2.31 branch later.

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch
Type: text/x-patch
Size: 15781 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20180720/b1745bfd/attachment.bin>


More information about the Binutils mailing list