* [PATCH] GAS fix section alignment for aarch64-pe
@ 2022-11-07 17:53 Zac Walker
2022-11-07 22:58 ` Alan Modra
0 siblings, 1 reply; 3+ messages in thread
From: Zac Walker @ 2022-11-07 17:53 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 1568 bytes --]
For the aarch64-pe target, section alignment for various values of
'.align' causes writing of coff files to fail.
This patch performs aligning in md_section_align as opposed to the
original approach in aarch64_handle_align. The change is specific to
the aarch64-pe target.
Thanks,
Zac
---
gas/config/tc-aarch64.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index f6fa158583..44ad510209 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -8290,13 +8290,22 @@ md_estimate_size_before_relax (fragS * fragp,
segT segtype ATTRIBUTE_UNUSED)
return 4;
}
-/* Round up a section size to the appropriate boundary. */
-
+/* Round up a COFF section size not needed for ELF */
+#ifdef OBJ_COFF
+valueT
+md_section_align (segT segment, valueT size)
+{
+ int align = bfd_section_alignment (segment);
+ valueT mask = ((valueT) 1 << align) - 1;
+ return (size + mask) & ~mask;
+}
+#else /* !OBJ_COFF */
valueT
md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
{
return size;
}
+#endif /* !OBJ_COFF */
/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
of an rs_align_code fragment.
@@ -8353,7 +8362,11 @@ aarch64_handle_align (fragS * fragP)
if (noop_size)
memcpy (p, aarch64_noop, noop_size);
+
+/* COFF sections may have unaligned fr_var and then be aligned in
md_section_align */
+#ifndef OBJ_COFF
fragP->fr_var = noop_size;
+#endif
}
/* Perform target specific initialisation of a frag.
--
2.25.1
[-- Attachment #2: 0001-GAS-fix-section-alignment-for-aarch64-pe.patch --]
[-- Type: application/octet-stream, Size: 1495 bytes --]
From 14943d8b45c9ffb4b463f7f12b60e6e79e0ba681 Mon Sep 17 00:00:00 2001
From: Zac Walker <zac.walker@linaro.org>
Date: Mon, 24 Oct 2022 22:21:39 +0200
Subject: [PATCH] GAS fix section alignment for aarch64-pe
---
gas/config/tc-aarch64.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index f6fa158583..44ad510209 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -8290,13 +8290,22 @@ md_estimate_size_before_relax (fragS * fragp, segT segtype ATTRIBUTE_UNUSED)
return 4;
}
-/* Round up a section size to the appropriate boundary. */
-
+/* Round up a COFF section size not needed for ELF */
+#ifdef OBJ_COFF
+valueT
+md_section_align (segT segment, valueT size)
+{
+ int align = bfd_section_alignment (segment);
+ valueT mask = ((valueT) 1 << align) - 1;
+ return (size + mask) & ~mask;
+}
+#else /* !OBJ_COFF */
valueT
md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
{
return size;
}
+#endif /* !OBJ_COFF */
/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
of an rs_align_code fragment.
@@ -8353,7 +8362,11 @@ aarch64_handle_align (fragS * fragP)
if (noop_size)
memcpy (p, aarch64_noop, noop_size);
+
+/* COFF sections may have unaligned fr_var and then be aligned in md_section_align */
+#ifndef OBJ_COFF
fragP->fr_var = noop_size;
+#endif
}
/* Perform target specific initialisation of a frag.
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] GAS fix section alignment for aarch64-pe
2022-11-07 17:53 [PATCH] GAS fix section alignment for aarch64-pe Zac Walker
@ 2022-11-07 22:58 ` Alan Modra
2022-11-08 18:40 ` zac.walker
0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2022-11-07 22:58 UTC (permalink / raw)
To: Zac Walker; +Cc: binutils
On Mon, Nov 07, 2022 at 06:53:35PM +0100, Zac Walker via Binutils wrote:
> For the aarch64-pe target, section alignment for various values of
> '.align' causes writing of coff files to fail.
> This patch performs aligning in md_section_align as opposed to the
> original approach in aarch64_handle_align. The change is specific to
> the aarch64-pe target.
This can't be correct since HANDLE_ALIGN and md_section_align perform
quite different functions. I don't think you should be changing
aarch64_handle_align. For example:
.text
.p2align 4
nop
.p2align 3
nop
The second p2align needs to continue emitting nops.
(Also, please fix your email client to *not* format lines. Wrapping
lines and changing white space breaks patches.)
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] GAS fix section alignment for aarch64-pe
2022-11-07 22:58 ` Alan Modra
@ 2022-11-08 18:40 ` zac.walker
0 siblings, 0 replies; 3+ messages in thread
From: zac.walker @ 2022-11-08 18:40 UTC (permalink / raw)
To: 'Alan Modra'; +Cc: binutils
Hi Alan, Thanks for the feedback.
You are correct - looks like I was over-focused on getting the write method working for various failing tests. Your example is
useful to show missing noops. From what I can see the changes to md_section_align seem necessary for COFF but unrelated to the write
issue. (Assuming the fix is HANDLE_ALIGN specific.)
I will re-work the patch and do more testing. Might take a few days.
Also, I will double check my email settings. Every email client I have tried (except git send-email) seems to break formatting one
way or another.
Cheers,
Zac
-----Original Message-----
From: Alan Modra <amodra@gmail.com>
Sent: 07 November 2022 23:58
To: Zac Walker <zac.walker@linaro.org>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] GAS fix section alignment for aarch64-pe
On Mon, Nov 07, 2022 at 06:53:35PM +0100, Zac Walker via Binutils wrote:
> For the aarch64-pe target, section alignment for various values of
> '.align' causes writing of coff files to fail.
> This patch performs aligning in md_section_align as opposed to the
> original approach in aarch64_handle_align. The change is specific to
> the aarch64-pe target.
This can't be correct since HANDLE_ALIGN and md_section_align perform quite different functions. I don't think you should be
changing aarch64_handle_align. For example:
.text
.p2align 4
nop
.p2align 3
nop
The second p2align needs to continue emitting nops.
(Also, please fix your email client to *not* format lines. Wrapping lines and changing white space breaks patches.)
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-08 18:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 17:53 [PATCH] GAS fix section alignment for aarch64-pe Zac Walker
2022-11-07 22:58 ` Alan Modra
2022-11-08 18:40 ` zac.walker
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).