Re: [Xen-devel] [PATCH v2] xen/x86: fix linker script to work with lld

2018-07-11 Thread Daniel Kiper
On Wed, Jul 11, 2018 at 01:46:56PM +0200, Roger Pau Monné wrote:
> On Wed, Jul 11, 2018 at 12:42:48PM +0200, Daniel Kiper wrote:
> > On Wed, Jul 11, 2018 at 12:25:21PM +0200, Roger Pau Monne wrote:
> > > lld (the llvm linker) has some issues with Xen linker script. It
> > > doesn't understand '||' in assert expressions:
> > >
> > > ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
> > > /root/src/xen/xen/common/symbols-dummy.o -o 
> > > /root/src/xen/xen/.xen-syms.0
> > > ld: error: xen.lds:260: malformed number: |
> > > >>> ASSERT(__image_base__ > (261 >> 8) * 0x) | 
> > > >>> (261 << 39))) + ((1 << 39) / 2)) + (64 << 30)) + (1 << 30)) + (1 << 
> > > >>> 30))) ||
> > > >>>   
> > > >>>   
> > > >>>   ^
> > >
> > > And doesn't work properly with the 'DEFINED(foo) ? foo : ...'
> > > expression:
> > >
> > > ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
> > > /root/src/xen/xen/common/symbols-dummy.o -o 
> > > /root/src/xen/xen/.xen-syms.0
> > > ld: error: xen.lds:233: symbol not found: efi
> > >
> > > Fix the first issue by using '|' instead of '||', and the second one
> > > by declaring the efi symbol as a weak symbol.
> > >
> > > Signed-off-by: Roger Pau Monné 
> > > ---
> > > Cc: Jan Beulich 
> > > Cc: Andrew Cooper 
> > > Cc: Daniel Kiper 
> > > ---
> > > Changes since v1:
> > >  - Export efi as a weak symbol in order to remove the DEFINED
> > >conditional in the linker script.
> > >  - Add a define for setting the weak attribute and replace existing
> > >users.
> >
> > May I ask you to split this patch into two separate patches?
> > One for __weak change and one for DEFINED() drop please.
>
> So to introduce and use __weak also for the efi variable and then drop
> the DEFINED in a following patch?
>
> Or switch efi to use __weak in the same patch where DEFINED is
> dropped?

The latter please.

Daniel

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2] xen/x86: fix linker script to work with lld

2018-07-11 Thread Roger Pau Monné
On Wed, Jul 11, 2018 at 12:42:48PM +0200, Daniel Kiper wrote:
> On Wed, Jul 11, 2018 at 12:25:21PM +0200, Roger Pau Monne wrote:
> > lld (the llvm linker) has some issues with Xen linker script. It
> > doesn't understand '||' in assert expressions:
> >
> > ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
> > /root/src/xen/xen/common/symbols-dummy.o -o 
> > /root/src/xen/xen/.xen-syms.0
> > ld: error: xen.lds:260: malformed number: |
> > >>> ASSERT(__image_base__ > (261 >> 8) * 0x) | (261 
> > >>> << 39))) + ((1 << 39) / 2)) + (64 << 30)) + (1 << 30)) + (1 << 30))) ||
> > >>> 
> > >>>   ^
> >
> > And doesn't work properly with the 'DEFINED(foo) ? foo : ...'
> > expression:
> >
> > ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
> > /root/src/xen/xen/common/symbols-dummy.o -o 
> > /root/src/xen/xen/.xen-syms.0
> > ld: error: xen.lds:233: symbol not found: efi
> >
> > Fix the first issue by using '|' instead of '||', and the second one
> > by declaring the efi symbol as a weak symbol.
> >
> > Signed-off-by: Roger Pau Monné 
> > ---
> > Cc: Jan Beulich 
> > Cc: Andrew Cooper 
> > Cc: Daniel Kiper 
> > ---
> > Changes since v1:
> >  - Export efi as a weak symbol in order to remove the DEFINED
> >conditional in the linker script.
> >  - Add a define for setting the weak attribute and replace existing
> >users.
> 
> May I ask you to split this patch into two separate patches?
> One for __weak change and one for DEFINED() drop please.

So to introduce and use __weak also for the efi variable and then drop
the DEFINED in a following patch?

Or switch efi to use __weak in the same patch where DEFINED is
dropped?

Roger.

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2] xen/x86: fix linker script to work with lld

2018-07-11 Thread Daniel Kiper
On Wed, Jul 11, 2018 at 12:25:21PM +0200, Roger Pau Monne wrote:
> lld (the llvm linker) has some issues with Xen linker script. It
> doesn't understand '||' in assert expressions:
>
> ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
> /root/src/xen/xen/common/symbols-dummy.o -o /root/src/xen/xen/.xen-syms.0
> ld: error: xen.lds:260: malformed number: |
> >>> ASSERT(__image_base__ > (261 >> 8) * 0x) | (261 
> >>> << 39))) + ((1 << 39) / 2)) + (64 << 30)) + (1 << 30)) + (1 << 30))) ||
> >>>   
> >>> ^
>
> And doesn't work properly with the 'DEFINED(foo) ? foo : ...'
> expression:
>
> ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
> /root/src/xen/xen/common/symbols-dummy.o -o /root/src/xen/xen/.xen-syms.0
> ld: error: xen.lds:233: symbol not found: efi
>
> Fix the first issue by using '|' instead of '||', and the second one
> by declaring the efi symbol as a weak symbol.
>
> Signed-off-by: Roger Pau Monné 
> ---
> Cc: Jan Beulich 
> Cc: Andrew Cooper 
> Cc: Daniel Kiper 
> ---
> Changes since v1:
>  - Export efi as a weak symbol in order to remove the DEFINED
>conditional in the linker script.
>  - Add a define for setting the weak attribute and replace existing
>users.

May I ask you to split this patch into two separate patches?
One for __weak change and one for DEFINED() drop please.

Daniel

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

[Xen-devel] [PATCH v2] xen/x86: fix linker script to work with lld

2018-07-11 Thread Roger Pau Monne
lld (the llvm linker) has some issues with Xen linker script. It
doesn't understand '||' in assert expressions:

ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
/root/src/xen/xen/common/symbols-dummy.o -o /root/src/xen/xen/.xen-syms.0
ld: error: xen.lds:260: malformed number: |
>>> ASSERT(__image_base__ > (261 >> 8) * 0x) | (261 << 
>>> 39))) + ((1 << 39) / 2)) + (64 << 30)) + (1 << 30)) + (1 << 30))) ||
>>> 
>>>   ^

And doesn't work properly with the 'DEFINED(foo) ? foo : ...'
expression:

ld-melf_x86_64_fbsd  -T xen.lds -N prelink.o --build-id=sha1 \
/root/src/xen/xen/common/symbols-dummy.o -o /root/src/xen/xen/.xen-syms.0
ld: error: xen.lds:233: symbol not found: efi

Fix the first issue by using '|' instead of '||', and the second one
by declaring the efi symbol as a weak symbol.

Signed-off-by: Roger Pau Monné 
---
Cc: Jan Beulich 
Cc: Andrew Cooper 
Cc: Daniel Kiper 
---
Changes since v1:
 - Export efi as a weak symbol in order to remove the DEFINED
   conditional in the linker script.
 - Add a define for setting the weak attribute and replace existing
   users.
---
 xen/arch/x86/xen.lds.S  | 4 +---
 xen/include/xen/compiler.h  | 2 ++
 xen/include/xen/efi.h   | 2 +-
 xen/include/xen/livepatch_payload.h | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 70afedd31d..9fa40a6d48 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -304,8 +304,6 @@ SECTIONS
   } :text
 #endif
 
-  efi = DEFINED(efi) ? efi : .;
-
   /* Sections to be discarded */
   /DISCARD/ : {
*(.exit.text)
@@ -331,7 +329,7 @@ SECTIONS
   .comment 0 : { *(.comment) }
 }
 
-ASSERT(__image_base__ > XEN_VIRT_START ||
+ASSERT(__image_base__ > XEN_VIRT_START |
__2M_rwdata_end <= XEN_VIRT_END - NR_CPUS * PAGE_SIZE,
"Xen image overlaps stubs area")
 
diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
index a7e05681c9..001f589655 100644
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -18,6 +18,8 @@
 
 #define __packed  __attribute__((__packed__))
 
+#define __weak__attribute__((weak))
+
 #if (!defined(__clang__) && (__GNUC__ == 4) && (__GNUC_MINOR__ < 5))
 #define unreachable() do {} while (1)
 #else
diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h
index 44b7d3ec3a..5678df72f9 100644
--- a/xen/include/xen/efi.h
+++ b/xen/include/xen/efi.h
@@ -21,7 +21,7 @@ struct efi {
 unsigned long smbios3;  /* SMBIOS v3 table */
 };
 
-extern struct efi efi;
+extern struct efi __weak efi;
 
 #ifndef __ASSEMBLY__
 
diff --git a/xen/include/xen/livepatch_payload.h 
b/xen/include/xen/livepatch_payload.h
index 8f38cc2c60..4a1a96d054 100644
--- a/xen/include/xen/livepatch_payload.h
+++ b/xen/include/xen/livepatch_payload.h
@@ -24,7 +24,7 @@ typedef void livepatch_unloadcall_t(void);
  * executed in series by the livepatch infrastructure at patch load time.
  */
 #define LIVEPATCH_LOAD_HOOK(_fn) \
-livepatch_loadcall_t *__attribute__((weak)) \
+livepatch_loadcall_t *__weak \
 const livepatch_load_data_##_fn __section(".livepatch.hooks.load") = 
_fn;
 
 /*
@@ -33,7 +33,7 @@ typedef void livepatch_unloadcall_t(void);
  * Same as LOAD hook with s/load/unload/
  */
 #define LIVEPATCH_UNLOAD_HOOK(_fn) \
- livepatch_unloadcall_t *__attribute__((weak)) \
+ livepatch_unloadcall_t *__weak \
 const livepatch_unload_data_##_fn __section(".livepatch.hooks.unload") 
= _fn;
 
 #endif /* __XEN_LIVEPATCH_PAYLOAD_H__ */
-- 
2.17.1


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel