Skip to contentSkip to conversation

x86: build with llvm 8 linker

PATCH In review Roger Pau Monne 4 participants 33 messages Jun 19, 2019 – Jun 25, 2019

lore
Share & tools
lore
#0 lore raw

cover x86: build with llvm 8 linker

Hello,

Current hypervisor code/build produces an invalid binary when linked with lld 8 (llvm linker). This is because lld 8 places orphaned sections at the beginning of the output file, thus displacing the multiboot headers.

In order to build a correct image with lld 8 make sure there are no orphaned sections, and also add a build-time check to assert the multiboot headers are present between the offset boundary given in the specification.

Roger Pau Monne (4):
xz: use initconst for hypervisor build
x86/linker: use DECL_SECTION uniformly
x86/linker: add a reloc section to ELF binary
x86: check for multiboot{1,2} header presence

 xen/arch/x86/Makefile      |  3 +++
 xen/arch/x86/xen.lds.S     | 14 +++++++++-----
 xen/common/decompress.h    |  2 ++
 xen/common/xz/dec_bcj.c    |  6 +++---
 xen/common/xz/dec_stream.c |  2 +-
 5 files changed, 18 insertions(+), 9 deletions(-)
Signature · 7 lines
2.20.1 (Apple Git-117)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/4 xz: use initconst for hypervisor build

Or else clang adds a .init.rodata.cst8 section to the resulting object file, which is not handled by the Xen linker script and can end up before the text section which contains the headers, thus resulting in a not usable binary.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/common/decompress.h    | 2 ++
 xen/common/xz/dec_bcj.c    | 6 +++---
 xen/common/xz/dec_stream.c | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
xen/common/decompress.h +2 -0
index 647b7b1e83..4a429bca12 100644
@@ -10,6 +10,7 @@
 #define STATIC
 #define INIT __init
 #define INITDATA __initdata
+#define INITCONST __initconst
 
 #define malloc xmalloc_bytes
 #define free xfree
@@ -22,6 +23,7 @@
 #define STATIC static
 #define INIT
 #define INITDATA
+#define INITCONST
 
 #define large_malloc malloc
 #define large_free free
xen/common/xz/dec_bcj.c +3 -3
index 86c1192199..0a9a45de2b 100644
@@ -87,10 +87,10 @@ static inline int INIT bcj_x86_test_msbyte(uint8_t b)
 
 static size_t INIT bcj_x86(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
 {
-	static const bool_t mask_to_allowed_status[8]
+	static const bool_t INITCONST mask_to_allowed_status[8]
 		= { true, true, true, false, true, false, false, false };
 
-	static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
+	static const uint8_t INITCONST mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
 
 	size_t i;
 	size_t prev_pos = (size_t)-1;
@@ -180,7 +180,7 @@ static size_t INIT bcj_powerpc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
 #ifdef XZ_DEC_IA64
 static size_t INIT bcj_ia64(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
 {
-	static const uint8_t branch_table[32] = {
+	static const uint8_t INITCONST branch_table[32] = {
 		0, 0, 0, 0, 0, 0, 0, 0,
 		0, 0, 0, 0, 0, 0, 0, 0,
 		4, 4, 6, 6, 0, 0, 7, 7,
xen/common/xz/dec_stream.c +1 -1
index b8b566307c..61eb2ffb55 100644
@@ -138,7 +138,7 @@ struct xz_dec {
 
 #ifdef XZ_DEC_ANY_CHECK
 /* Sizes of the Check field with different Check IDs */
-static const uint8_t check_sizes[16] = {
+static const uint8_t INITCONST check_sizes[16] = {
 	0,
 	4, 4, 4,
 	8, 8, 8,
Signature · 7 lines
2.20.1 (Apple Git-117)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [Xen-devel] [PATCH 1/4] xz: use initconst for hypervisor build

Quoted 6 lines · Roger Pau Monne

Or else clang adds a .init.rodata.cst8 section to the resulting object file, which is not handled by the Xen linker script and can end up before the text section which contains the headers, thus resulting in a not usable binary.

I think Clang is actually adding a .rodata.cst8 section, and the bulk objcopy turns it into .init.rodata.cst8.

This is a good change so Reviewed-by: Andrew Cooper <[email protected]> (subject to some clarity over the exact section), but I also think this is needed as well:

xen/arch/x86/xen.lds.S +0 -0
index cb42dc8..4f23059 100644
@@ -206,8 +206,7 @@ SECTIONS

 #endif

        *(.init.rodata)
-       *(.init.rodata.rel)
-       *(.init.rodata.str*)
+       *(.init.rodata.*)

        . = ALIGN(POINTER_ALIGN);
        __setup_start = .;
@@ -221,8 +220,7 @@ SECTIONS
        __initcall_end = .;

        *(.init.data)
-       *(.init.data.rel)
-       *(.init.data.rel.*)
+       *(.init.data.*)
        . = ALIGN(4);
        __trampoline_rel_start = .;
        *(.trampoline_rel)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [Xen-devel] [PATCH 1/4] xz: use initconst for hypervisor build

Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:09, <[email protected]> wrote:
Quoted 6 lines · Roger Pau Monne

Or else clang adds a .init.rodata.cst8 section to the resulting object file, which is not handled by the Xen linker script and can end up before the text section which contains the headers, thus resulting in a not usable binary.

I think Clang is actually adding a .rodata.cst8 section, and the bulk objcopy turns it into .init.rodata.cst8.

This is a good change so Reviewed-by: Andrew Cooper <[email protected]> (subject to some clarity over the exact section), but I also think this is needed as well:

xen/arch/x86/xen.lds.S +1 -2
index cb42dc8..4f23059 100644
@@ -206,8 +206,7 @@ SECTIONS
 #endif
 
        *(.init.rodata)
-       *(.init.rodata.rel)
-       *(.init.rodata.str*)
+       *(.init.rodata.*)
 
        . = ALIGN(POINTER_ALIGN);
        __setup_start = .;

xen/arch/x86/xen.lds.S SECTIONS · line 226

Quoted 9 lines
xen/arch/x86/xen.lds.S +1 -2
@@ -221,8 +220,7 @@ SECTIONS
        __initcall_end = .;
 
        *(.init.data)
-       *(.init.data.rel)
-       *(.init.data.rel.*)
+       *(.init.data.*)
        . = ALIGN(4);
        __trampoline_rel_start = .;
        *(.trampoline_rel)

And the same thing then also for Arm.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Re: [Xen-devel] [PATCH 1/4] xz: use initconst for hypervisor build

In reply to Roger Pau Monne
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

Or else clang adds a .init.rodata.cst8 section to the resulting object file, which is not handled by the Xen linker script and can end up before the text section which contains the headers, thus resulting in a not usable binary.

To be honest I'd prefer if we went with just the change suggested by Andrew, getting the linker script back in line with SPECIAL_DATA_SECTIONS. The static const items in the decompressors were left un-annotated intentionally, since the .rodata.* thingies want/need taking care of anyway. After all you won't (I hope) suggest also annotating the various string literals.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [Xen-devel] [PATCH 1/4] xz: use initconst for hypervisor build

Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

Or else clang adds a .init.rodata.cst8 section to the resulting object file, which is not handled by the Xen linker script and can end up before the text section which contains the headers, thus resulting in a not usable binary.

Quoted 6 lines

To be honest I'd prefer if we went with just the change suggested by Andrew, getting the linker script back in line with SPECIAL_DATA_SECTIONS. The static const items in the decompressors were left un-annotated intentionally, since the .rodata.* thingies want/need taking care of anyway. After all you won't (I hope) suggest also annotating the various string literals.

OK, I think regardless of the rest of the lld 8 series it is worth sending the linker script change in order to prevent having this orphaned section.

Andrew, since you where the one to propose it, could you please send a formal patch?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

PATCH 2/4 x86/linker: use DECL_SECTION uniformly

In reply to Roger Pau Monne

Replace the two open-coded EFI related section declarations with the usage of DECL_SECTION. This is a preparatory change for also adding a reloc section to the ELF binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/xen.lds.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/xen.lds.S +2 -2
index cb42dc8fda..98a99444c2 100644
@@ -298,12 +298,12 @@ SECTIONS
 
 #ifdef EFI
   . = ALIGN(4);
-  .reloc : {
+  DECL_SECTION(.reloc) {
     *(.reloc)
   } :text
   /* Trick the linker into setting the image size to exactly 16Mb. */
   . = ALIGN(__section_alignment__);
-  .pad : {
+  DECL_SECTION(.pad) {
     . = ALIGN(MB(16));
   } :text
 #endif
Signature · 7 lines
2.20.1 (Apple Git-117)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 2/4
#7 lore raw

Re: [Xen-devel] [PATCH 2/4] x86/linker: use DECL_SECTION uniformly

Quoted 5 lines · Roger Pau Monne

Replace the two open-coded EFI related section declarations with the usage of DECL_SECTION. This is a preparatory change for also adding a reloc section to the ELF binary.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw

PATCH 3/4 x86/linker: add a reloc section to ELF binary

In reply to Roger Pau Monne

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/xen.lds.S | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
xen/arch/x86/xen.lds.S +8 -4
index 98a99444c2..82103ef1da 100644
@@ -175,6 +175,14 @@ SECTIONS
   } :text
 #endif
 #endif
+
+#ifdef XEN_BUILD_EFI
+  . = ALIGN(4);
+  DECL_SECTION(.reloc) {
+    *(.reloc)
+  } :text
+#endif
+
   _erodata = .;
 
   . = ALIGN(SECTION_ALIGN);
@@ -297,10 +305,6 @@ SECTIONS
   __2M_rwdata_end = .;
 
 #ifdef EFI
-  . = ALIGN(4);
-  DECL_SECTION(.reloc) {
-    *(.reloc)
-  } :text
   /* Trick the linker into setting the image size to exactly 16Mb. */
   . = ALIGN(__section_alignment__);
   DECL_SECTION(.pad) {
Signature · 7 lines
2.20.1 (Apple Git-117)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 1 line · Roger Pau Monne

If the hypervisor has been built with EFI support (ie: multiboot2).

Seeing as this continues the sentence from the subject, it should start without a capital.  Otherwise the result is werd to read.

Quoted 3 lines

This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Really?  How can this be a legitimate transformation for the linker to make?

Quoted 6 lines

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

The content of .relocs is transformed via mkreloc to become __base_relocs_{start,end} and shouldn't exist into the final linked image AFAICT.

Since the MB1/MB2 builds aren't relocatable, I think we might be able to get away with simply excluding them in the non-EFI build.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:20, <[email protected]> wrote:
Quoted 5 lines · Roger Pau Monne

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

The content of .relocs is transformed via mkreloc to become __base_relocs_{start,end} and shouldn't exist into the final linked image AFAICT.

The labels are referenced from code, and hence ...

Quoted 2 lines

Since the MB1/MB2 builds aren't relocatable, I think we might be able to get away with simply excluding them in the non-EFI build.

... this won't be possible without further trickery, I'm afraid.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#11 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

In reply to Andrew Cooper
Quoted 11 lines · Andrew Cooper
Quoted 1 line · Roger Pau Monne

If the hypervisor has been built with EFI support (ie: multiboot2).

Seeing as this continues the sentence from the subject, it should start without a capital.  Otherwise the result is werd to read.

Quoted 3 lines

This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Really?  How can this be a legitimate transformation for the linker to make?

I've already submitted a bug report:

https://bugs.llvm.org/show_bug.cgi?id=42327

GNU ld behaviour is to place orphaned sections at the end.

Quoted 10 lines
Quoted 6 lines

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

The content of .relocs is transformed via mkreloc to become __base_relocs_{start,end} and shouldn't exist into the final linked image AFAICT.

__base_relocs_{start/end} is actually what's contained in the .relocs section, or at least that was mny impression based on the contents of xen/arch/x86/efi/relocs-dummy.S

Quoted 2 lines

Since the MB1/MB2 builds aren't relocatable, I think we might be able to get away with simply excluding them in the non-EFI build.

Hm, OK. I'm slightly loss then. I've taken a look at the history of xen/arch/x86/efi/relocs-dummy.S and it's not clear to me why such a dummy file was added. My guess is that it's done in order to prevent missing symbols errors. If that's the case I guess the code that makes use of such symbols can be guarded, and the dummy file removed?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#12 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 16:30, <[email protected]> wrote:
Quoted 2 lines · Andrew Cooper

Since the MB1/MB2 builds aren't relocatable, I think we might be able to get away with simply excluding them in the non-EFI build.

Hm, OK. I'm slightly loss then. I've taken a look at the history of xen/arch/x86/efi/relocs-dummy.S and it's not clear to me why such a dummy file was added. My guess is that it's done in order to prevent missing symbols errors. If that's the case I guess the code that makes use of such symbols can be guarded, and the dummy file removed?

Missing symbols errors - yes. But how would you remove the dummy one, which is a place holder in stage 1 linking for what will be real data in stages 2 and 3? I don't think we should ignore unresolved symbols in stage 1.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

In reply to Roger Pau Monne
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

On the whole, seeing all these adjustments for a linker behavior I'm tempted to call buggy, I'm not sure whether we shouldn't instead declare this linker version as unusable with Xen. I can't imagine that they're going to leave it as it is right now.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Or do we prefer to leave .reloc orphaned in the ELF build?

Quoted 4 lines

On the whole, seeing all these adjustments for a linker behavior I'm tempted to call buggy, I'm not sure whether we shouldn't instead declare this linker version as unusable with Xen. I can't imagine that they're going to leave it as it is right now.

I've already submitted a bug report, let's see if this can be fixed and backported to 8. It's a shame because previous versions of lld worked just fine, and I would consider this a lld regression.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Also a remark regarding the title - in my builds there already is a .reloc section in the ELF images, so "add" doesn't really seem correct to me. It sits right after .rodata, and I would it doesn't get folded into there because - for some reason - .rodata is actually marked writable.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 32 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Quoted 5 lines

Also a remark regarding the title - in my builds there already is a .reloc section in the ELF images, so "add" doesn't really seem correct to me. It sits right after .rodata, and I would it doesn't get folded into there because - for some reason - .rodata is actually marked writable.

AFAICT .rodata is marked writable because it contains .data.param and .data.rel.ro. I'm unsure why we need .data.rel.ro, I would assume that once the final binary has been linked .data.rel.ro would be empty, since there's no run time linking or relocation as Xen is a standalone binary.

Regarding .data.param it should be renamed to .rodata.param, and I should take a look at why it's marked as 'WA' instead of 'A'.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 21.06.19 at 13:46, <[email protected]> wrote:
Quoted 32 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Quoted 5 lines

Also a remark regarding the title - in my builds there already is a .reloc section in the ELF images, so "add" doesn't really seem correct to me. It sits right after .rodata, and I would it doesn't get folded into there because - for some reason - .rodata is actually marked writable.

Quoted 5 lines

AFAICT .rodata is marked writable because it contains .data.param and .data.rel.ro. I'm unsure why we need .data.rel.ro, I would assume that once the final binary has been linked .data.rel.ro would be empty, since there's no run time linking or relocation as Xen is a standalone binary.

No - contents of sections don't get moved to other sections while linking, unless instructed so by the linker script. In all the relocatable objects there's going to be .data.rel.ro, and hence the linker script has to put them somewhere (or leave it to default placement by the linker).

Hmm, thinking about it - are you perhaps mixing up .data.rel / .data.rel.ro with .rel.data / .rela.data?

Quoted 2 lines

Regarding .data.param it should be renamed to .rodata.param, and I should take a look at why it's marked as 'WA' instead of 'A'.

Well, there's no "const" on the structure instantiations.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#18 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 46 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 21.06.19 at 13:46, <[email protected]> wrote:
Quoted 32 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Quoted 5 lines

Also a remark regarding the title - in my builds there already is a .reloc section in the ELF images, so "add" doesn't really seem correct to me. It sits right after .rodata, and I would it doesn't get folded into there because - for some reason - .rodata is actually marked writable.

Quoted 5 lines

AFAICT .rodata is marked writable because it contains .data.param and .data.rel.ro. I'm unsure why we need .data.rel.ro, I would assume that once the final binary has been linked .data.rel.ro would be empty, since there's no run time linking or relocation as Xen is a standalone binary.

Quoted 5 lines

No - contents of sections don't get moved to other sections while linking, unless instructed so by the linker script. In all the relocatable objects there's going to be .data.rel.ro, and hence the linker script has to put them somewhere (or leave it to default placement by the linker).

Right, so as long as we place .data.rel.ro inside of .rodata the resulting section is always going to be writable, due to the input .data.rel.ro being writable.

Quoted 2 lines

Hmm, thinking about it - are you perhaps mixing up .data.rel / .data.rel.ro with .rel.data / .rela.data?

Yes, I think I messed up. As you say, contents of sections don't move unless explicitly done by the linker script.

Quoted 4 lines
Quoted 2 lines

Regarding .data.param it should be renamed to .rodata.param, and I should take a look at why it's marked as 'WA' instead of 'A'.

Well, there's no "const" on the structure instantiations.

I think there is indeed a const on the instantiation, see __param macro in init.h which is used in the declarations done with __rtparam.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

In reply to Jan Beulich
Quoted 25 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 6 lines
Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

I would not drop .reloc section from xen-syms because it can be useful for "manual" EFI image relocs generation. However, I am not strongly tied to it. If you wish to drop it go ahead. I can readd it latter if I get back to my new PE build work.

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#20 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 33 lines · Daniel Kiper
Quoted 25 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 6 lines
Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Quoted 4 lines

I would not drop .reloc section from xen-syms because it can be useful for "manual" EFI image relocs generation. However, I am not strongly tied to it. If you wish to drop it go ahead. I can readd it latter if I get back to my new PE build work.

Do you mean that the dummy .reloc section added to non-PE builds can be dropped? (ie: remove xen/arch/x86/efi/relocs-dummy.S from the build)

I'm slightly lost, .reloc begin a section that's explicitly added to non-PE builds by relocs-dummy.S I assumed it was needed for some reason.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#21 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 25.06.19 at 10:10, <[email protected]> wrote:
Quoted 33 lines · Daniel Kiper
Quoted 31 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Quoted 7 lines
Quoted 4 lines

I would not drop .reloc section from xen-syms because it can be useful for "manual" EFI image relocs generation. However, I am not strongly tied to it. If you wish to drop it go ahead. I can readd it latter if I get back to my new PE build work.

Do you mean that the dummy .reloc section added to non-PE builds can be dropped? (ie: remove xen/arch/x86/efi/relocs-dummy.S from the build)

Given my earlier reply it's not clear to me what you mean by "remove" here. As a result ...

Quoted 3 lines

I'm slightly lost, .reloc begin a section that's explicitly added to non-PE builds by relocs-dummy.S I assumed it was needed for some reason.

... it's also not clear what exactly you mean here, and hence whether there's any reason needed beyond the reference to the two bounding symbols by efi_arch_relocate_image().

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 46 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 25.06.19 at 10:10, <[email protected]> wrote:
Quoted 33 lines · Daniel Kiper
Quoted 31 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Quoted 7 lines
Quoted 4 lines

I would not drop .reloc section from xen-syms because it can be useful for "manual" EFI image relocs generation. However, I am not strongly tied to it. If you wish to drop it go ahead. I can readd it latter if I get back to my new PE build work.

Do you mean that the dummy .reloc section added to non-PE builds can be dropped? (ie: remove xen/arch/x86/efi/relocs-dummy.S from the build)

Given my earlier reply it's not clear to me what you mean by "remove" here. As a result ...

Quoted 7 lines
Quoted 3 lines

I'm slightly lost, .reloc begin a section that's explicitly added to non-PE builds by relocs-dummy.S I assumed it was needed for some reason.

... it's also not clear what exactly you mean here, and hence whether there's any reason needed beyond the reference to the two bounding symbols by efi_arch_relocate_image().

Sorry for not being clear. By remove I mean git rm xen/arch/x86/efi/relocs-dummy.S and fix the build, like the diff appended below.

Is there any reason we should keep the dummy .reloc in the ELF output?

Thanks, Roger.
---8<---

xen/arch/x86/efi/Makefile +1 -1
index 4bc0a196e9..5849604766 100644
@@ -11,6 +11,6 @@ $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4)
 $(EFIOBJ): CFLAGS-stack-boundary := $(cflags-stack-boundary)
 
 obj-y := stub.o
-obj-$(XEN_BUILD_EFI) := $(EFIOBJ) relocs-dummy.o
+obj-$(XEN_BUILD_EFI) := $(EFIOBJ)
 extra-$(XEN_BUILD_EFI) += buildid.o
 nocov-$(XEN_BUILD_EFI) += stub.o
xen/arch/x86/efi/efi-boot.h +7 -0
index 7a13a30bc0..2cf440e2ae 100644
@@ -39,6 +39,7 @@ extern const intpte_t __page_tables_start[], __page_tables_end[];
 #define PE_BASE_RELOC_HIGHLOW  3
 #define PE_BASE_RELOC_DIR64   10
 
+#ifdef XEN_BUILD_PE
 extern const struct pe_base_relocs {
     u32 rva;
     u32 size;
@@ -97,6 +98,12 @@ static void __init efi_arch_relocate_image(unsigned long delta)
         base_relocs = (const void *)(base_relocs->entries + i + (i & 1));
     }
 }
+#else /* !XEN_BUILD_PE */
+static void __init efi_arch_relocate_image(unsigned long delta)
+{
+    ASSERT_UNREACHABLE();
+}
+#endif /* XEN_BUILD_PE */
 
 extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
 extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];
xen/arch/x86/efi/relocs-dummy.S deleted +0 -11
deleted file mode 100644
index d928a82d53..0000000000
@@ -1,11 +0,0 @@
-
-	.section .reloc, "a", @progbits
-	.balign 4
-GLOBAL(__base_relocs_start)
-	.long 0
-	.long 8
-GLOBAL(__base_relocs_end)
-
-	.globl VIRT_START, ALT_START
-	.equ VIRT_START, XEN_VIRT_START
-	.equ ALT_START, XEN_VIRT_END

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#23 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 51 lines · Roger Pau Monné
Quoted 50 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 25.06.19 at 10:10, <[email protected]> wrote:
Quoted 33 lines · Daniel Kiper
Quoted 31 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 17:06, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

If the hypervisor has been built with EFI support (ie: multiboot2). This allows to position the .reloc section correctly in the output binary, or else the linker might place .reloc before the .text section.

Note that the .reloc section is moved before .bss for two reasons: in order for the resulting binary to not contain any section with data after .bss, so that the file size can be smaller than the loaded memory size, and because the data it contains is read-only, so it belongs with the other sections containing read-only data.

Quoted 7 lines
Quoted 4 lines

While this may be fine for ELF, I'm afraid it would be calling for subtle issues with xen.efi (i.e. the PE binary): There a .reloc section is generally expected to come after "normal" data sections.

OK, would you like me to leave the .reloc section at the previous position for EFI builds then?

Well, this part is a requirement, not a question of me liking you to do so.

Quoted 1 line

Or do we prefer to leave .reloc orphaned in the ELF build?

Daniel might have an opinion here with his plans to actually add relocations there in the non-linker-generated-PE build. I don't have a strong opinion either way, as long as the current method of building gets left as is (or even simplified).

Quoted 7 lines
Quoted 4 lines

I would not drop .reloc section from xen-syms because it can be useful for "manual" EFI image relocs generation. However, I am not strongly tied to it. If you wish to drop it go ahead. I can readd it latter if I get back to my new PE build work.

Do you mean that the dummy .reloc section added to non-PE builds can be dropped? (ie: remove xen/arch/x86/efi/relocs-dummy.S from the build)

Given my earlier reply it's not clear to me what you mean by "remove" here. As a result ...

Quoted 3 lines

I'm slightly lost, .reloc begin a section that's explicitly added to non-PE builds by relocs-dummy.S I assumed it was needed for some reason.

Quoted 7 lines
Quoted 3 lines

... it's also not clear what exactly you mean here, and hence whether there's any reason needed beyond the reference to the two bounding symbols by efi_arch_relocate_image().

Sorry for not being clear. By remove I mean git rm xen/arch/x86/efi/relocs-dummy.S and fix the build, like the diff appended below.

The chunk below will not work because relocs-dummy is also needed by the EFI build. I'm however lost at why this is required, and the commit message that introduced the file (bf6501a62e) doesn't add any reasoning.

Is maybe .reloc mandatory for PE format?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#24 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 25.06.19 at 14:48, <[email protected]> wrote:
Quoted 3 lines · Roger Pau Monné

Sorry for not being clear. By remove I mean git rm xen/arch/x86/efi/relocs-dummy.S and fix the build, like the diff appended below.

Quoted 6 lines

The chunk below will not work because relocs-dummy is also needed by the EFI build. I'm however lost at why this is required, and the commit message that introduced the file (bf6501a62e) doesn't add any reasoning.

Is maybe .reloc mandatory for PE format?

Yes, almost. You _can_ have one without .reloc, but then you're tied to it loading at the linked address. That's fine with an ordinary boot loader, but it's not an option when this is to get loaded just like a normal binary, without knowing at which address it'll be placed. Remember that the EFI boot environment runs in (pseudo)physical mode, i.e. there's a 1:1 mapping between linear and physical addresses. Therefore there's no way to predict a memory range that's always going to be available (and that hence xen.efi could be linked to load at).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#25 lore raw

Re: [Xen-devel] [PATCH 3/4] x86/linker: add a reloc section to ELF binary

In reply to Roger Pau Monné
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 25.06.19 at 13:08, <[email protected]> wrote:

Sorry for not being clear. By remove I mean git rm xen/arch/x86/efi/relocs-dummy.S and fix the build, like the diff appended below.

Is there any reason we should keep the dummy .reloc in the ELF output?

Yes, there is. And yes, I was afraid you'd mean this.

xen/arch/x86/efi/efi-boot.h extern const intpte_t __page_tables_start[], __page_tables_end[]; · line 42

Quoted 7 lines
xen/arch/x86/efi/efi-boot.h +1 -0
@@ -39,6 +39,7 @@ extern const intpte_t __page_tables_start[], __page_tables_end[];
 #define PE_BASE_RELOC_HIGHLOW  3
 #define PE_BASE_RELOC_DIR64   10
 
+#ifdef XEN_BUILD_PE

This is an identifier available to Makefiles only. You also can't propagate it to .c files, as these get compiled just once to produce _both_ PE and ELF binary. So while what you suggest may build, it'll result in a broken xen.efi.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#26 lore raw

PATCH 4/4 x86: check for multiboot{1, 2} header presence

In reply to Roger Pau Monne

After building the hypervisor binary. Note that the check is performed by searching for the magic header value at the start of the binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/Makefile | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/Makefile +3 -0
index 8a8d8f060f..9bb3bf6e6c 100644
@@ -102,6 +102,9 @@ syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
 	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
+	# Check for multiboot{1,2} headers
+	od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null
+	od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null
 
 ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
 
Signature · 7 lines
2.20.1 (Apple Git-117)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#27 lore raw

Re: [Xen-devel] [PATCH 4/4] x86: check for multiboot{1, 2} header presence

Quoted 17 lines · Roger Pau Monne

After building the hypervisor binary. Note that the check is performed by searching for the magic header value at the start of the binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/Makefile | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/Makefile +0 -0
index 8a8d8f060f..9bb3bf6e6c 100644

xen/arch/x86/Makefile syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := · line 107

Quoted 6 lines
xen/arch/x86/Makefile +3 -0
@@ -102,6 +102,9 @@ syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
 	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
+	# Check for multiboot{1,2} headers
+	od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null
+	od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null

Neat solution.  Is grep -q portable ?

~Andrew

xen/arch/x86/Makefile syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := · line 110

Quoted 3 lines
xen/arch/x86/Makefile +0 -0
 ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#28 lore raw

Re: [Xen-devel] [PATCH 4/4] x86: check for multiboot{1, 2} header presence

Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Roger Pau Monne

After building the hypervisor binary. Note that the check is performed by searching for the magic header value at the start of the binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 13 lines

xen/arch/x86/Makefile syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := · line 107

Quoted 11 lines
xen/arch/x86/Makefile +3 -0
index 8a8d8f060f..9bb3bf6e6c 100644
@@ -102,6 +102,9 @@ syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
 	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
+	# Check for multiboot{1,2} headers
+	od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null
+	od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null

Neat solution.  Is grep -q portable ?

It is, but grep -q closes the pipe on the first match, and then od will return an error. Note sure whether there's a way to workaround this issue, but I think the above is simple enough.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#29 lore raw

Re: [Xen-devel] [PATCH 4/4] x86: check for multiboot{1, 2} header presence

Quoted 26 lines · Roger Pau Monné
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Roger Pau Monne

After building the hypervisor binary. Note that the check is performed by searching for the magic header value at the start of the binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 12 lines

xen/arch/x86/Makefile syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := · line 107

Quoted 11 lines
xen/arch/x86/Makefile +3 -0
index 8a8d8f060f..9bb3bf6e6c 100644
@@ -102,6 +102,9 @@ syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
 	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
 	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
+	# Check for multiboot{1,2} headers
+	od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null
+	od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null

Neat solution.  Is grep -q portable ?

Quoted 3 lines

It is, but grep -q closes the pipe on the first match, and then od will return an error. Note sure whether there's a way to workaround this issue, but I think the above is simple enough.

In which case, Reviewed-by: Andrew Cooper <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#30 lore raw

Re: [Xen-devel] [PATCH 4/4] x86: check for multiboot{1, 2} header presence

In reply to Roger Pau Monne
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

After building the hypervisor binary. Note that the check is performed by searching for the magic header value at the start of the binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/Makefile | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/Makefile +0 -0
index 8a8d8f060f..9bb3bf6e6c 100644
@@ -102,6 +102,9 @@ 

syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32

xen/arch/x86/Makefile syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := · line 107

Quoted 5 lines
xen/arch/x86/Makefile +3 -0
 	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
 	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
+	# Check for multiboot{1,2} headers
+	od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null
+	od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null

What's the behavior when a signature is _not _ found? Will $(TARGET) get deleted (by make)? I don't think it would (as we don't specific .DELETE_ON_ERROR anywhere), so a subsequent rebuild may not even execute this rule, and hence may look to be successful despite it not actually having been.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#31 lore raw

Re: [Xen-devel] [PATCH 4/4] x86: check for multiboot{1, 2} header presence

Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

After building the hypervisor binary. Note that the check is performed by searching for the magic header value at the start of the binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/Makefile | 3 +++
 1 file changed, 3 insertions(+)
xen/arch/x86/Makefile +0 -0
index 8a8d8f060f..9bb3bf6e6c 100644
@@ -102,6 +102,9 @@ 

syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32

xen/arch/x86/Makefile +1 -0
 	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
 	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . __2M_rwdata_end$$/0x\1/p'`
+	# Check for multiboot{1,2} headers
Quoted 8 lines

xen/arch/x86/Makefile syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := · line 107

Quoted 2 lines
xen/arch/x86/Makefile +2 -0
+	od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null
+	od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null

What's the behavior when a signature is _not _ found? Will $(TARGET) get deleted (by make)? I don't think it would (as we don't specific .DELETE_ON_ERROR anywhere), so a subsequent rebuild may not even execute this rule, and hence may look to be successful despite it not actually having been.

Oh, right. It should be:

od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null || (rm -rf $(TARGET); exit 1) od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null || (rm -rf $(TARGET); exit 1)

Would you be OK with the above runes?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#32 lore raw

Re: [Xen-devel] [PATCH 4/4] x86: check for multiboot{1, 2} header presence

Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 16:40, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 19.06.19 at 13:02, <[email protected]> wrote:

After building the hypervisor binary. Note that the check is performed by searching for the magic header value at the start of the binary.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>

---
 xen/arch/x86/Makefile | 3 +++
 1 file changed, 3 insertions(+)
Quoted 9 lines

xen/arch/x86/Makefile

Quoted 9 lines
xen/arch/x86/Makefile +0 -0
index 8a8d8f060f..9bb3bf6e6c 100644
@@ -102,6 +102,9 @@ 

syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
$(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32

xen/arch/x86/Makefile +0 -0
 	./boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TARGET) $(XEN_IMG_OFFSET) \
 	               `$(NM) $(TARGET)-syms | sed -ne 's/^\([^ ]*\) . 

__2M_rwdata_end$$/0x\1/p'`

Quoted 9 lines

xen/arch/x86/Makefile syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := · line 107

Quoted 3 lines
xen/arch/x86/Makefile +3 -0
+	# Check for multiboot{1,2} headers
+	od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null
+	od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null

What's the behavior when a signature is _not _ found? Will $(TARGET) get deleted (by make)? I don't think it would (as we don't specific .DELETE_ON_ERROR anywhere), so a subsequent rebuild may not even execute this rule, and hence may look to be successful despite it not actually having been.

Quoted 6 lines

Oh, right. It should be:

od -t x4 -N 8192 $(TARGET) | grep 1badb002 > /dev/null || (rm -rf $(TARGET); exit 1) od -t x4 -N 32768 $(TARGET) | grep e85250d6 > /dev/null || (rm -rf $(TARGET); exit 1)

Would you be OK with the above runes?

Not really, I'm afraid. This still wouldn't cope with an interrupted build. I think it needs to be made work via an intermediate target, or some other make trickery.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel