Skip to contentSkip to conversation

xen: Linker scripts synchronization

PATCH In review Michal Orzel 2 participants 6 messages Apr 11, 2022

lore
Share & tools
lore
#0 lore raw

v5 cover xen: Linker scripts synchronization

This patch series aims to do the first step towards linker scripts synchronization. Linker scripts for arm and x86 share a lot of common sections and in order to make the process of changing/improving/syncing them, these sections shall be defined in just one place.

The first patch creates an empty header file xen.lds.h to store the constructs mutual to both x86 and arm linker scripts. It also includes this header in the scripts.

The second patch populates xen.lds.h with the first portion of common macros and replaces the original contructs with these helpers.

Michal Orzel (2):
xen: Introduce a header to store common linker scripts content
xen: Populate xen.lds.h and make use of its macros

 xen/arch/arm/xen.lds.S    |  45 +++----------
 xen/arch/x86/xen.lds.S    |  97 +++------------------------
 xen/include/xen/xen.lds.h | 137 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 157 insertions(+), 122 deletions(-)
 create mode 100644 xen/include/xen/xen.lds.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/2 xen: Introduce a header to store common linker scripts content

Both x86 and arm linker scripts share quite a lot of common content. It is difficult to keep syncing them up, thus introduce a new header in include/xen called xen.lds.h to store the internals mutual to all the linker scripts.

Include this header in linker scripts for x86 and arm. This patch serves as an intermediate step before populating xen.lds.h and making use of its content in the linker scripts later on.

---
Changes since v4:
-rebased
Changes since v2,v3:
-none
Changes since v1:
-rename header to xen.lds.h to be coherent with Linux kernel -include empty header in linker scripts

---
 xen/arch/arm/xen.lds.S    | 1 +
 xen/arch/x86/xen.lds.S    | 1 +
 xen/include/xen/xen.lds.h | 8 ++++++++
 3 files changed, 10 insertions(+)
 create mode 100644 xen/include/xen/xen.lds.h
xen/arch/arm/xen.lds.S +1 -0
index ad7f966f0e..d20e5e94e4 100644
@@ -4,6 +4,7 @@
 
 #include <xen/cache.h>
 #include <xen/lib.h>
+#include <xen/xen.lds.h>
 #include <asm/page.h>
 #undef ENTRY
 #undef ALIGN
xen/arch/x86/xen.lds.S +1 -0
index 6926e88e54..1fcd8ab7c5 100644
@@ -3,6 +3,7 @@
 
 #include <xen/cache.h>
 #include <xen/lib.h>
+#include <xen/xen.lds.h>
 #include <asm/page.h>
 #undef ENTRY
 #undef ALIGN
xen/include/xen/xen.lds.h new file +8 -0
new file mode 100644
index 0000000000..dd292fa7dc
@@ -0,0 +1,8 @@
+#ifndef __XEN_LDS_H__
+#define __XEN_LDS_H__
+
+/*
+ * Common macros to be used in architecture specific linker scripts.
+ */
+
+#endif /* __XEN_LDS_H__ */
Signature · 1 line
2.25.1
Acked-by on v5 1/2
#2 lore raw

Re: [PATCH v5 1/2] xen: Introduce a header to store common linker scripts content

Hi Michal,

Quoted 11 lines · Michal Orzel

Both x86 and arm linker scripts share quite a lot of common content. It is difficult to keep syncing them up, thus introduce a new header in include/xen called xen.lds.h to store the internals mutual to all the linker scripts.

Include this header in linker scripts for x86 and arm. This patch serves as an intermediate step before populating xen.lds.h and making use of its content in the linker scripts later on.

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

PATCH v5 2/2 xen: Populate xen.lds.h and make use of its macros

In reply to Michal Orzel

Populate header file xen.lds.h with the first portion of macros storing constructs common to x86 and arm linker scripts. Replace the original constructs with these helpers.

No functional improvements to x86 linker script.

Making use of common macros improves arm linker script with:
- explicit list of debug sections that otherwise are seen as "orphans" by the linker. This will allow to fix issues after enabling linker option --orphan-handling one day,
- extended list of discarded section to include: .discard, destructors related sections, .fini_array which can reference .text.exit,
- sections not related to debugging that are placed by ld.lld. Even though we do not support linking with LLD on Arm, these sections do not cause problem to GNU ld,

As we are replacing hardcoded boundary specified as an argument to ALIGN function with POINTER_ALIGN, this changes the alignment in HYPFS_PARAM construct for arm32 from 8 to 4. It is fine as there are no 64bit values used in struct param_hypfs.

Please note that this patch does not aim to perform the full sync up between the linker scripts. It creates a base for further work.

---
Changes since v4:
-update commit msg with a note about changed alignment for HYPFS_PARAM on arm32 Changes since v3:
-use POINTER_ALIGN in debug sections when needed
-modify comment about ELF_DETAILS_SECTIONS
Changes since v2:
-refactor commit msg
-move constructs together with surrounding ifdefery
-list constructs other than *_SECTIONS in alphabetical order
-add comment about EFI vs EFI support
Changes since v1:
-merge x86 and arm changes into single patch
-do not propagate issues by generalizing CTORS
-extract sections not related to debugging into separate macro -get rid of _SECTION suffix in favor of using more meaningful suffixes

---
 xen/arch/arm/xen.lds.S    |  44 +++----------
 xen/arch/x86/xen.lds.S    |  96 +++-------------------------
 xen/include/xen/xen.lds.h | 129 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+), 122 deletions(-)
xen/arch/arm/xen.lds.S +10 -34
index d20e5e94e4..1e986e211f 100644
@@ -69,12 +69,7 @@ SECTIONS
        *(.proc.info)
        __proc_info_end = .;
 
-#ifdef CONFIG_HAS_VPCI
-       . = ALIGN(POINTER_ALIGN);
-       __start_vpci_array = .;
-       *(SORT(.data.vpci.*))
-       __end_vpci_array = .;
-#endif
+       VPCI_ARRAY
   } :text
 
 #if defined(BUILD_ID)
@@ -110,12 +105,7 @@ SECTIONS
        *(.data.schedulers)
        __end_schedulers_array = .;
 
-#ifdef CONFIG_HYPFS
-       . = ALIGN(8);
-       __paramhypfs_start = .;
-       *(.data.paramhypfs)
-       __paramhypfs_end = .;
-#endif
+       HYPFS_PARAM
 
        *(.data .data.*)
        CONSTRUCTORS
@@ -179,12 +169,7 @@ SECTIONS
        *(.altinstructions)
        __alt_instructions_end = .;
 
-#ifdef CONFIG_DEBUG_LOCK_PROFILE
-       . = ALIGN(POINTER_ALIGN);
-       __lock_profile_start = .;
-       *(.lockprofile.data)
-       __lock_profile_end = .;
-#endif
+       LOCK_PROFILE_DATA
 
        *(.init.data)
        *(.init.data.rel)
@@ -223,22 +208,13 @@ SECTIONS
   /* Section for the device tree blob (if any). */
   .dtb : { *(.dtb) } :text
 
-  /* Sections to be discarded */
-  /DISCARD/ : {
-       *(.exit.text)
-       *(.exit.data)
-       *(.exitcall.exit)
-       *(.eh_frame)
-  }
-
-  /* Stabs debugging sections.  */
-  .stab 0 : { *(.stab) }
-  .stabstr 0 : { *(.stabstr) }
-  .stab.excl 0 : { *(.stab.excl) }
-  .stab.exclstr 0 : { *(.stab.exclstr) }
-  .stab.index 0 : { *(.stab.index) }
-  .stab.indexstr 0 : { *(.stab.indexstr) }
-  .comment 0 : { *(.comment) }
+  DWARF2_DEBUG_SECTIONS
+
+  DISCARD_SECTIONS
+
+  STABS_DEBUG_SECTIONS
+
+  ELF_DETAILS_SECTIONS
 }
 
 /*
xen/arch/x86/xen.lds.S +8 -88

140 lines not on this page · raw message

xen/include/xen/xen.lds.h +129 -0

133 lines not on this page · raw message

Signature · 1 line
2.25.1
Reviewed-by on v5 2/2
#4 lore raw

Re: [PATCH v5 2/2] xen: Populate xen.lds.h and make use of its macros

Hi Michal,

Quoted 21 lines · Michal Orzel

Populate header file xen.lds.h with the first portion of macros storing constructs common to x86 and arm linker scripts. Replace the original constructs with these helpers.

No functional improvements to x86 linker script.

Making use of common macros improves arm linker script with:
- explicit list of debug sections that otherwise are seen as "orphans" by the linker. This will allow to fix issues after enabling linker option --orphan-handling one day,
- extended list of discarded section to include: .discard, destructors related sections, .fini_array which can reference .text.exit,
- sections not related to debugging that are placed by ld.lld. Even though we do not support linking with LLD on Arm, these sections do not cause problem to GNU ld,

As we are replacing hardcoded boundary specified as an argument to ALIGN function with POINTER_ALIGN, this changes the alignment in HYPFS_PARAM construct for arm32 from 8 to 4. It is fine as there are no 64bit values used in struct param_hypfs.

Quoted 5 lines

Please note that this patch does not aim to perform the full sync up between the linker scripts. It creates a base for further work.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
In reply to Michal Orzel

Hi Michal,

Quoted 9 lines · Michal Orzel

This patch series aims to do the first step towards linker scripts synchronization. Linker scripts for arm and x86 share a lot of common sections and in order to make the process of changing/improving/syncing them, these sections shall be defined in just one place.

The first patch creates an empty header file xen.lds.h to store the constructs mutual to both x86 and arm linker scripts. It also includes this header in the scripts.

Quoted 6 lines

The second patch populates xen.lds.h with the first portion of common macros and replaces the original contructs with these helpers.

Michal Orzel (2):
xen: Introduce a header to store common linker scripts content
xen: Populate xen.lds.h and make use of its macros

I have committed the two patches.

Cheers,

Signature · 1 line
Julien Grall