From: Frediano Ziglio <frediano.ziglio@cloud.com>
To: xen-devel@lists.xenproject.org
Cc: "Frediano Ziglio" <frediano.ziglio@cloud.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Julien Grall" <julien@xen.org>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: [PATCH] x86/boot: Handle better alignment for 32 bit code
Date: Tue, 14 Jan 2025 09:59:14 +0000 [thread overview]
Message-ID: <20250114095914.93226-1-frediano.ziglio@cloud.com> (raw)
Output file didn't have correct alignment.
Allows alignment into data or code up to 2mb.
Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
---
xen/arch/x86/boot/Makefile | 8 ++++----
xen/tools/combine_two_binaries.py | 7 ++++++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/xen/arch/x86/boot/Makefile b/xen/arch/x86/boot/Makefile
index 13d4583173..9a8ecba7aa 100644
--- a/xen/arch/x86/boot/Makefile
+++ b/xen/arch/x86/boot/Makefile
@@ -40,8 +40,8 @@ LD32 := $(LD) $(subst x86_64,i386,$(LDFLAGS_DIRECT))
# are affected by both text_diff and text_gap. Ensure the sum of gap and diff
# is greater than 2^16 so that any 16bit relocations if present in the object
# file turns into a build-time error.
-text_gap := 0x010200
-text_diff := 0x408020
+text_gap := 0x01c240
+text_diff := 0x7e3dc0
$(obj)/build32.base.lds: AFLAGS-y += -DGAP=$(text_gap) -DTEXT_DIFF=$(text_diff)
$(obj)/build32.offset.lds: AFLAGS-y += -DGAP=$(text_gap) -DTEXT_DIFF=$(text_diff) -DAPPLY_OFFSET
@@ -69,7 +69,6 @@ $(obj)/built-in-32.%.bin: $(obj)/build32.%.lds $(obj)/built-in-32.tmp.o
$(LD32) $(orphan-handling-y) -N -T $< -o $(@:bin=o) $(filter %.o,$^)
$(NM) -p --format=bsd $(@:bin=o) > $(@:bin=map)
$(OBJCOPY) -j .text -O binary $(@:bin=o) $@
- rm -f $(@:bin=o)
quiet_cmd_combine = GEN $@
cmd_combine = \
@@ -80,6 +79,7 @@ cmd_combine = \
--bin1 $(obj)/built-in-32.base.bin \
--bin2 $(obj)/built-in-32.offset.bin \
--map $(obj)/built-in-32.base.map \
+ --align $(shell $(OBJDUMP) -h $(obj)/built-in-32.base.o|sed '/text.*2\*\*/ {s/.*2\*\*//;p;}; d') \
--exports cmdline_parse_early,reloc,reloc_trampoline32 \
--output $@
@@ -90,4 +90,4 @@ $(obj)/built-in-32.S: $(obj)/built-in-32.base.bin $(obj)/built-in-32.offset.bin
$(srctree)/tools/combine_two_binaries.py FORCE
$(call if_changed,combine)
-clean-files := built-in-32.*.bin built-in-32.*.map build32.*.lds
+clean-files := built-in-32.*.bin built-in-32.*.map built-in-32.*.o build32.*.lds
diff --git a/xen/tools/combine_two_binaries.py b/xen/tools/combine_two_binaries.py
index 581e57cbc0..8e587c24fb 100755
--- a/xen/tools/combine_two_binaries.py
+++ b/xen/tools/combine_two_binaries.py
@@ -26,6 +26,10 @@ parser.add_argument('--text-diff', dest='text_diff',
required=True,
type=auto_int,
help='Difference between code section start')
+parser.add_argument('--align', dest='align',
+ default=2,
+ type=auto_int,
+ help='Alignment in power of 2')
parser.add_argument('--output', dest='output',
help='Output file')
parser.add_argument('--map', dest='mapfile',
@@ -93,7 +97,7 @@ if size1 > size2:
file1, file2 = file2, file1
size1, size2 = size2, size1
if size2 != size1 + gap:
- raise Exception('File sizes do not match')
+ raise Exception('File sizes do not match %d != %d + %d' % (size2, size1, gap))
del size2
file1.seek(0, 0)
@@ -219,6 +223,7 @@ print('''/*
* File autogenerated by combine_two_binaries.py DO NOT EDIT
*/''', file=out)
print('\t' + args.section_header, file=out)
+print('\t.p2align\t' + str(args.align), file=out)
print('obj32_start:', file=out)
output(out)
print('\n\t.section .note.GNU-stack,"",@progbits', file=out)
--
2.34.1
next reply other threads:[~2025-01-14 9:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-14 9:59 Frediano Ziglio [this message]
2025-01-14 11:40 ` [PATCH] x86/boot: Handle better alignment for 32 bit code Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250114095914.93226-1-frediano.ziglio@cloud.com \
--to=frediano.ziglio@cloud.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.