public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch, BFD, AArch64] Fix PT_GNU_PROPERTY alignment issue
@ 2019-06-05 10:07 Sudakshina Das
  2019-06-06 11:12 ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: Sudakshina Das @ 2019-06-05 10:07 UTC (permalink / raw)
  To: binutils; +Cc: nd, nickc, Richard Earnshaw, Ramana Radhakrishnan

[-- Attachment #1: Type: text/plain, Size: 988 bytes --]

Hi

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.

Built and regression tested on aarch64-none-linux-gnu and added new 
tests to check the alignment.

Is this ok to commit?

Thanks
Sudi

bfd/ChangeLog:

2019-xx-xx  Sudakshina Das  <sudi.das@arm.com>

	* elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Set
	alignment of the new gnu property section.

ld/ChangeLog:

2019-xx-xx  Sudakshina Das  <sudi.das@arm.com>

	* 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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rb11317.patch --]
[-- Type: text/x-patch; name="rb11317.patch", Size: 3391 bytes --]

diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c
index d16f2ecc1ff53f6667993162bcd2d69889ec2585..350a2c7a24f8cded9a61072f46f31a4433a3ac70 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/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index c1a94957aae77a82926dbfa4f9790fb3e387665d..d0a588c5f92158f4fa39ed0078c6abd1bd699a4d 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 0000000000000000000000000000000000000000..35dd28f9ef75681a1a357eb08426901a9664e4fc
--- /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: --force-bti -e main
+#readelf: -l --wide
+#target: *linux*
+#warning: .*property-bti-pac4.*: warning: BTI turned on by --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 0000000000000000000000000000000000000000..c5961073e566f9ce2d7740adbafb840a700e9bc5
--- /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] --force-bti -e main
+#readelf: -l --wide
+#target: *linux*
+#warning: .*property-bti-pac4.*: warning: BTI turned on by --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 0000000000000000000000000000000000000000..a1122ff8e653de2776bcc1902661482ad0e0ee66
--- /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

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

* Re: [Patch, BFD, AArch64] Fix PT_GNU_PROPERTY alignment issue
  2019-06-05 10:07 [Patch, BFD, AArch64] Fix PT_GNU_PROPERTY alignment issue Sudakshina Das
@ 2019-06-06 11:12 ` Nick Clifton
  2019-06-06 11:34   ` Sudakshina Das
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2019-06-06 11:12 UTC (permalink / raw)
  To: Sudakshina Das, binutils; +Cc: nd, Richard Earnshaw, Ramana Radhakrishnan

Hi Sudi,

> bfd/ChangeLog:
> 2019-xx-xx  Sudakshina Das  <sudi.das@arm.com>
> 
> 	* elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Set
> 	alignment of the new gnu property section.
> 
> ld/ChangeLog:
> 2019-xx-xx  Sudakshina Das  <sudi.das@arm.com>
> 
> 	* 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.

Approved - please apply.

Cheers
  Nick


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

* Re: [Patch, BFD, AArch64] Fix PT_GNU_PROPERTY alignment issue
  2019-06-06 11:12 ` Nick Clifton
@ 2019-06-06 11:34   ` Sudakshina Das
  0 siblings, 0 replies; 3+ messages in thread
From: Sudakshina Das @ 2019-06-06 11:34 UTC (permalink / raw)
  To: nickc, binutils; +Cc: nd, Richard Earnshaw, Ramana Radhakrishnan

Hi Nick

On 06/06/2019 12:12, Nick Clifton wrote:
> Hi Sudi,
> 
>> bfd/ChangeLog:
>> 2019-xx-xx  Sudakshina Das  <sudi.das@arm.com>
>>
>> 	* elfxx-aarch64.c (_bfd_aarch64_elf_link_setup_gnu_properties): Set
>> 	alignment of the new gnu property section.
>>
>> ld/ChangeLog:
>> 2019-xx-xx  Sudakshina Das  <sudi.das@arm.com>
>>
>> 	* 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.
> 
> Approved - please apply.

Thanks, both patches now committed!

Sudi
> 
> Cheers
>    Nick
> 
> 


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

end of thread, other threads:[~2019-06-06 11:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 10:07 [Patch, BFD, AArch64] Fix PT_GNU_PROPERTY alignment issue Sudakshina Das
2019-06-06 11:12 ` Nick Clifton
2019-06-06 11:34   ` Sudakshina Das

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).