From 237df8fe1863bb47fcf71ce125cd962666173aaa Mon Sep 17 00:00:00 2001 From: Sudakshina Das Date: Thu, 6 Jun 2019 12:27:41 +0100 Subject: [PATCH] [BFD, AArch64] Fix PT_GNU_PROPERTY alignment issue If the new GNU property section was being created by the linker (this will happen only if none of the inputs have any GNU property section but the command line to the linker forces a bti with --force-bti), the alignment of the section and hence the program header of PT_GNU_PROPERTY type was not being set correctly. This patch fixes this issue. bfd/ChangeLog: 2019-06-06 Sudakshina Das * elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Set alignment of the new gnu property section. ld/ChangeLog: 2019-06-06 Sudakshina Das * testsuite/ld-aarch64/aarch64-elf.exp: Add new tests. * testsuite/ld-aarch64/property-bti-pac4-a.d: New test. * testsuite/ld-aarch64/property-bti-pac4-b.d: New test. * testsuite/ld-aarch64/property-bti-pac4.s: New test. --- bfd/ChangeLog | 5 +++++ bfd/elfxx-aarch64.c | 8 +++++++ ld/ChangeLog | 7 +++++++ ld/testsuite/ld-aarch64/aarch64-elf.exp | 2 ++ ld/testsuite/ld-aarch64/property-bti-pac4-a.d | 11 ++++++++++ ld/testsuite/ld-aarch64/property-bti-pac4-b.d | 11 ++++++++++ ld/testsuite/ld-aarch64/property-bti-pac4.s | 21 +++++++++++++++++++ 7 files changed, 65 insertions(+) create mode 100644 ld/testsuite/ld-aarch64/property-bti-pac4-a.d create mode 100644 ld/testsuite/ld-aarch64/property-bti-pac4-b.d create mode 100644 ld/testsuite/ld-aarch64/property-bti-pac4.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 69624fee8e..058e971f78 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2019-06-06 Sudakshina Das + + * elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Set + alignment of the new gnu property section. + 2019-06-06 Sudakshina Das * bfd-in.h: Change comment. diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c index 1249008035..33af6c22e1 100644 --- a/bfd/elfxx-aarch64.c +++ b/bfd/elfxx-aarch64.c @@ -695,6 +695,7 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info, bfd *pbfd; bfd *ebfd = NULL; elf_property *prop; + unsigned align; uint32_t gnu_prop = *gprop; @@ -743,6 +744,13 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info, info->callbacks->einfo ( _("%F%P: failed to create GNU property section\n")); + align = (bfd_get_mach (ebfd) & bfd_mach_aarch64_ilp32) ? 2 : 3; + if (!bfd_set_section_alignment (ebfd, sec, align)) + { + info->callbacks->einfo (_("%F%pA: failed to align section\n"), + sec); + } + elf_section_type (sec) = SHT_NOTE; } } diff --git a/ld/ChangeLog b/ld/ChangeLog index 4d747af1a9..acbbf94637 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2019-06-06 Sudakshina Das + + * testsuite/ld-aarch64/aarch64-elf.exp: Add new tests. + * testsuite/ld-aarch64/property-bti-pac4-a.d: New test. + * testsuite/ld-aarch64/property-bti-pac4-b.d: New test. + * testsuite/ld-aarch64/property-bti-pac4.s: New test. + 2019-06-06 Sudakshina Das * NEWS: Update options names. diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index c1a94957aa..d0a588c5f9 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -381,6 +381,8 @@ run_dump_test_lp64 "pie-bind-locally" run_dump_test "property-bti-pac1" run_dump_test "property-bti-pac2" run_dump_test "property-bti-pac3" +run_dump_test "property-bti-pac4-a" +run_dump_test "property-bti-pac4-b" run_dump_test "bti-plt-1" run_dump_test "bti-plt-2" diff --git a/ld/testsuite/ld-aarch64/property-bti-pac4-a.d b/ld/testsuite/ld-aarch64/property-bti-pac4-a.d new file mode 100644 index 0000000000..d9aa5cfa44 --- /dev/null +++ b/ld/testsuite/ld-aarch64/property-bti-pac4-a.d @@ -0,0 +1,11 @@ +#name: PT_GNU_PROPERTY alignment +#source: property-bti-pac4.s +#as: -mabi=lp64 +#ld: -z force-bti -e main +#readelf: -l --wide +#target: *linux* +#warning: .*property-bti-pac4.*: warning: BTI turned on by -z force-bti.* + +#... + GNU_PROPERTY .* +0x8 +#... diff --git a/ld/testsuite/ld-aarch64/property-bti-pac4-b.d b/ld/testsuite/ld-aarch64/property-bti-pac4-b.d new file mode 100644 index 0000000000..02f9fc5aca --- /dev/null +++ b/ld/testsuite/ld-aarch64/property-bti-pac4-b.d @@ -0,0 +1,11 @@ +#name: PT_GNU_PROPERTY alignment ILP32 +#source: property-bti-pac4.s +#as: -mabi=ilp32 +#ld: -m [aarch64_choose_ilp32_emul] -z force-bti -e main +#readelf: -l --wide +#target: *linux* +#warning: .*property-bti-pac4.*: warning: BTI turned on by -z force-bti.* + +#... + GNU_PROPERTY .* +0x4 +#... diff --git a/ld/testsuite/ld-aarch64/property-bti-pac4.s b/ld/testsuite/ld-aarch64/property-bti-pac4.s new file mode 100644 index 0000000000..a1122ff8e6 --- /dev/null +++ b/ld/testsuite/ld-aarch64/property-bti-pac4.s @@ -0,0 +1,21 @@ + .arch armv8-a + .file "t.c" + .text + .align 2 + .p2align 3,,7 + .global f + .type f, %function +f: + add w0, w0, 1 + ret + .size f, .-f + .section .text.startup,"ax",@progbits + .align 2 + .p2align 3,,7 + .global main + .type main, %function +main: + mov w0, 6 + ret + .size main, .-main + .section .note.GNU-stack,"",@progbits -- 2.34.1