deal with GOT stuff for RISC-V
v2 cover deal with GOT stuff for RISC-V
The patch series introduces things to deal with GOT stuff whichwas faced during the work on [1].
Initially, the issue was with 'la' pseudo instruction, which transformed to 'aupic/l{w|d} GOT' instead of 'auipc/addi'.
The transformation dependson .option {nopic, pic} directive or compiler flags.
Right now, 'la' transforms to 'auipc/l{w|d}', which in case of cpu0_boot_stack[] will lead to the usage of _GLOBAL_OFFSET_TABLE_and addresses inside GOT sections will be relative to linker time addresses.
At least there are two reasons for that:
1. GCC compiler used in RISCV64 container is compiled with --enable-default-pie flag.
2. GCC spec file for the RISC-V architecture by default enabled -fpic:
[user@49295ae49cbe build]$ riscv64-linux-gnu-gcc -dumpspecs | grep -i pic
--traditional-format %(subtarget_asm_debugging_spec) %{fno-pie|fno- PIE|fno-pic|fno-PIC:;:-fpic} %{march=*} %{mabi=*} %{mno-relax} %{mbig- endian} %{mlittle-endian} %(subtarget_asm_spec)%{misa-spec=*}which means that -fpic is enabled if none of the following options are present on the command line: fno-pie, -fno-PIE, -fno-pic, -fno-PIC
To resolve that, it was added EMBEDDED_EXTRA_CFLAGS to RISCV's CFLAGS as it was done for other architecture.
To catch use cases when GOT things will be produced by something was createthe second patch of the patch series:
[xen/riscv: add explicit check that.got{.plt} is empty] which add .got&.got.plt sections to xen.lds.S and alsoadds asserts to check that the mentioned sections are empty otherwise, it will be produced a compilation error with the message that the sections aren't empty.
[1]:
https://lore.kernel.org/xen-devel/[email protected]/T/#t
---
Changes in V2:
* The patch [1] was refactored and lead to the patch [xen/riscv: add EMBEDDED_EXTRA_CFLAGS to CFLAGS].
* In addition to the patch [1] was created another patch [xen/riscv: add explicit check that .got{.plt} is empty] to be sure that .got{.plt} sections weren't produced.
---
Oleksii Kurochko (2):
xen/riscv: add EMBEDDED_EXTRA_CFLAGS to CFLAGS
xen/riscv: add explicit check that .got{.plt} is empty
xen/arch/riscv/arch.mk | 2 ++ xen/arch/riscv/xen.lds.S | 13 +++++++++++++ 2 files changed, 15 insertions(+)
Signature · 1 line
2.39.2
PATCH v2 1/2 xen/riscv: add EMBEDDED_EXTRA_CFLAGS to CFLAGS
The patch is needed to keep all address of cpu0_boot_stack PC-relative.
Pseudoinstruction 'la' can be transformed to 'auipc/addi' or 'auipc/l{w|d}'. It depends on the .option directive: nopic and pic or compiler flags.
Right now, 'la' transforms to 'auipc/l{w|d}', which in case of cpu0_boot_stack[] will lead to the usage of _GLOBAL_OFFSET_TABLE_ where all addresses will be without counting that it might happen that linker address != load address ( so addresses inside got sections will be relative to linker time ).
It happens becuase the compiler from riscv64 docker compiled with --enable-default-pie:
[user@49295ae49cbe build]$ riscv64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-linux-gnu/12.2.0/lto-wrapper
Target: riscv64-linux-gnu
Configured with: /build/riscv64-linux-gnu-gcc/src/gcc-12.2.0/configure --prefix=/usr --program-prefix=riscv64-linux-gnu- --with-local- prefix=/usr/riscv64-linux-gnu --with-sysroot=/usr/riscv64-linux-gnu -- with-build-sysroot=/usr/riscv64-linux-gnu --libdir=/usr/lib -- libexecdir=/usr/lib --target=riscv64-linux-gnu --host=x86_64-pc-linux- gnu --build=x86_64-pc-linux-gnu --with-system-zlib --with-isl --with- linker-hash-style=gnu --disable-nls --disable-libunwind-exceptions -- disable-libstdcxx-pch --disable-libssp --disable-multilib --disable- werror --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-gnu-unique-object - -enable-linker-build-id --enable-lto --enable-plugin --enable-install- libiberty --enable-gnu-indirect-function --enable-default-pie --enable- checking=release
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (GCC)
Looking at gcc spec file for the RISC-V architecture:
[user@49295ae49cbe build]$ riscv64-linux-gnu-gcc -dumpspecs | grep -i pic
--traditional-format %(subtarget_asm_debugging_spec) %{fno-pie|fno- PIE|fno-pic|fno-PIC:;:-fpic} %{march=*} %{mabi=*} %{mno-relax} %{mbig- endian} %{mlittle-endian} %(subtarget_asm_spec)%{misa-spec=*}
which means that -fpic is enabled if none of the following options are present on the command line:
-fno-pie
-fno-PIE
-fno-pic
-fno-PIC
That's the reasons why 'la' is transformed to 'aupic/l{w|d} GOT' and not be dependent on the toolchain used.
---
Changes in V2:
* instead of changing 'la' to 'lla' to keep cpu0_boot_stack PC-relative it was updated CFLAGS with EMBEDDED_EXTRA_CFLAGS which contains -fno-PIE thereby 'la' will be transformed to 'auipc/addi' without GOT usage.
* update the commit message with additional details.
--- xen/arch/riscv/arch.mk | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/riscv/arch.mk +2 -0
@@ -1,6 +1,8 @@ ######################################## # RISCV-specific definitions +$(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) + CFLAGS-$(CONFIG_RISCV_64) += -mabi=lp64 riscv-march-$(CONFIG_RISCV_ISA_RV64G) := rv64g
Signature · 1 line
2.39.2
Re: [PATCH v2 1/2] xen/riscv: add EMBEDDED_EXTRA_CFLAGS to CFLAGS
Quoted 50 lines · Oleksii Kurochko
The patch is needed to keep all address of
cpu0_boot_stackPC-relative.Pseudoinstruction 'la' can be transformed to 'auipc/addi' or 'auipc/l{w|d}'. It depends on the .option directive: nopic and pic or compiler flags.
Right now, 'la' transforms to 'auipc/l{w|d}', which in case of cpu0_boot_stack[] will lead to the usage of _GLOBAL_OFFSET_TABLE_ where all addresses will be without counting that it might happen that linker address != load address ( so addresses inside got sections will be relative to linker time ).
It happens becuase the compiler from riscv64 docker compiled with --enable-default-pie:
[user@49295ae49cbe build]$ riscv64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-linux-gnu/12.2.0/lto-wrapper
Target: riscv64-linux-gnu
Configured with: /build/riscv64-linux-gnu-gcc/src/gcc-12.2.0/configure --prefix=/usr --program-prefix=riscv64-linux-gnu- --with-local- prefix=/usr/riscv64-linux-gnu --with-sysroot=/usr/riscv64-linux-gnu -- with-build-sysroot=/usr/riscv64-linux-gnu --libdir=/usr/lib -- libexecdir=/usr/lib --target=riscv64-linux-gnu --host=x86_64-pc-linux- gnu --build=x86_64-pc-linux-gnu --with-system-zlib --with-isl --with- linker-hash-style=gnu --disable-nls --disable-libunwind-exceptions -- disable-libstdcxx-pch --disable-libssp --disable-multilib --disable- werror --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-gnu-unique-object - -enable-linker-build-id --enable-lto --enable-plugin --enable-install- libiberty --enable-gnu-indirect-function --enable-default-pie --enable- checking=release
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (GCC)Looking at gcc spec file for the RISC-V architecture:
[user@49295ae49cbe build]$ riscv64-linux-gnu-gcc -dumpspecs | grep -i pic
--traditional-format %(subtarget_asm_debugging_spec) %{fno-pie|fno- PIE|fno-pic|fno-PIC:;:-fpic} %{march=*} %{mabi=*} %{mno-relax} %{mbig- endian} %{mlittle-endian} %(subtarget_asm_spec)%{misa-spec=*}
which means that -fpic is enabled if none of the following options are present on the command line:
-fno-pie
-fno-PIE
-fno-pic
-fno-PIC
Quoted 4 lines
That's the reasons why 'la' is transformed to 'aupic/l{w|d} GOT' and not be dependent on the toolchain used.
Signed-off-by Oleksii Kurochko <[email protected]>
There may also want to be Suggested-by to both Andrew and me.
Jan
Re: [PATCH v2 1/2] xen/riscv: add EMBEDDED_EXTRA_CFLAGS to CFLAGS
In reply to Oleksii KurochkoQuoted 51 lines · Oleksii Kurochko
The patch is needed to keep all address of
cpu0_boot_stackPC-relative.Pseudoinstruction 'la' can be transformed to 'auipc/addi' or 'auipc/l{w|d}'. It depends on the .option directive: nopic and pic or compiler flags.
Right now, 'la' transforms to 'auipc/l{w|d}', which in case of cpu0_boot_stack[] will lead to the usage of _GLOBAL_OFFSET_TABLE_ where all addresses will be without counting that it might happen that linker address != load address ( so addresses inside got sections will be relative to linker time ).
It happens becuase the compiler from riscv64 docker compiled with --enable-default-pie:
[user@49295ae49cbe build]$ riscv64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-linux-gnu-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-linux-gnu/12.2.0/lto-wrapper
Target: riscv64-linux-gnu
Configured with: /build/riscv64-linux-gnu-gcc/src/gcc-12.2.0/configure --prefix=/usr --program-prefix=riscv64-linux-gnu- --with-local- prefix=/usr/riscv64-linux-gnu --with-sysroot=/usr/riscv64-linux-gnu -- with-build-sysroot=/usr/riscv64-linux-gnu --libdir=/usr/lib -- libexecdir=/usr/lib --target=riscv64-linux-gnu --host=x86_64-pc-linux- gnu --build=x86_64-pc-linux-gnu --with-system-zlib --with-isl --with- linker-hash-style=gnu --disable-nls --disable-libunwind-exceptions -- disable-libstdcxx-pch --disable-libssp --disable-multilib --disable- werror --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-gnu-unique-object - -enable-linker-build-id --enable-lto --enable-plugin --enable-install- libiberty --enable-gnu-indirect-function --enable-default-pie --enable- checking=release
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (GCC)Looking at gcc spec file for the RISC-V architecture:
[user@49295ae49cbe build]$ riscv64-linux-gnu-gcc -dumpspecs | grep -i pic
--traditional-format %(subtarget_asm_debugging_spec) %{fno-pie|fno- PIE|fno-pic|fno-PIC:;:-fpic} %{march=*} %{mabi=*} %{mno-relax} %{mbig- endian} %{mlittle-endian} %(subtarget_asm_spec)%{misa-spec=*}
which means that -fpic is enabled if none of the following options are present on the command line:
-fno-pie
-fno-PIE
-fno-pic
-fno-PIC
Quoted 4 lines
That's the reasons why 'la' is transformed to 'aupic/l{w|d} GOT' and not be dependent on the toolchain used.
Signed-off-by Oleksii Kurochko <[email protected]>
Alistair
Quoted 28 lines
---
Changes in V2:
* instead of changing 'la' to 'lla' to keepcpu0_boot_stackPC-relative it was updated CFLAGS withEMBEDDED_EXTRA_CFLAGSwhich contains -fno-PIE thereby 'la' will be transformed to 'auipc/addi' without GOT usage.
* update the commit message with additional details.--- xen/arch/riscv/arch.mk | 2 ++ 1 file changed, 2 insertions(+)xen/arch/riscv/arch.mk +2
-1@@ -1,6 +1,8 @@ ######################################## # RISCV-specific definitions +$(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) + CFLAGS-$(CONFIG_RISCV_64) += -mabi=lp64 riscv-march-$(CONFIG_RISCV_ISA_RV64G) := rv64g --2.39.2
PATCH v2 2/2 xen/riscv: add explicit check that .got{.plt} is empty
In reply to Oleksii KurochkoThe GOT sections usage should be avoided in the hypervisor so to catch such use cases earlier when GOT things are produced the patch introduces .got and .got.plt sections and adds asserts that they're empty.
The sections won't be created until they remain empty otherwise the asserts would cause early failure.
---
Changes in V2:
* the patch was introduced in patch series v2.
--- xen/arch/riscv/xen.lds.S | 13 +++++++++++++ 1 file changed, 13 insertions(+)
xen/arch/riscv/xen.lds.S +13 -0
@@ -1,3 +1,4 @@ +#include <xen/lib.h> #include <xen/xen.lds.h> #undef ENTRY
@@ -123,6 +124,15 @@ SECTIONS *(SORT(.init_array.*)) __ctors_end = .; } :text + + .got : { + *(.got) + } : text + + .got.plt : { + *(.got.plt) + } : text + . = ALIGN(POINTER_ALIGN); __init_end = .;
@@ -156,3 +166,6 @@ SECTIONS ELF_DETAILS_SECTIONS } + +ASSERT(!SIZEOF(.got), ".got non-empty") +ASSERT(!SIZEOF(.got.plt), ".got.plt non-empty")
Signature · 1 line
2.39.2
Re: [PATCH v2 2/2] xen/riscv: add explicit check that .got{.plt} is empty
Quoted 9 lines · Oleksii Kurochko
The GOT sections usage should be avoided in the hypervisor so to catch such use cases earlier when GOT things are produced the patch introduces .got and .got.plt sections and adds asserts that they're empty.
The sections won't be created until they remain empty otherwise the asserts would cause early failure.
Signed-off-by Oleksii Kurochko <[email protected]>
And again a Suggested-by to Andrew perhaps.
Jan
Re: [PATCH v2 2/2] xen/riscv: add explicit check that .got{.plt} is empty
In reply to Oleksii KurochkoQuoted 10 lines · Oleksii Kurochko
The GOT sections usage should be avoided in the hypervisor so to catch such use cases earlier when GOT things are produced the patch introduces .got and .got.plt sections and adds asserts that they're empty.
The sections won't be created until they remain empty otherwise the asserts would cause early failure.
Signed-off-by Oleksii Kurochko <[email protected]>
Alistair
Quoted 43 lines
---
Changes in V2:
* the patch was introduced in patch series v2.--- xen/arch/riscv/xen.lds.S | 13 +++++++++++++ 1 file changed, 13 insertions(+)xen/arch/riscv/xen.lds.S +13
-1@@ -1,3 +1,4 @@ +#include <xen/lib.h> #include <xen/xen.lds.h> #undef ENTRY@@ -123,6 +124,15 @@ SECTIONS *(SORT(.init_array.*)) __ctors_end = .; } :text + + .got : { + *(.got) + } : text + + .got.plt : { + *(.got.plt) + } : text + . = ALIGN(POINTER_ALIGN); __init_end = .;@@ -156,3 +166,6 @@ SECTIONS ELF_DETAILS_SECTIONS } + +ASSERT(!SIZEOF(.got), ".got non-empty") +ASSERT(!SIZEOF(.got.plt), ".got.plt non-empty") --2.39.2
Quoted 3 lines · Oleksii Kurochko
Oleksii Kurochko (2):
xen/riscv: addEMBEDDED_EXTRA_CFLAGSto CFLAGS xen/riscv: add explicit check that .got{.plt} is empty
Quoted 6 lines · Andrew Cooper
Quoted 3 lines · Oleksii Kurochko
Oleksii Kurochko (2):
xen/riscv: addEMBEDDED_EXTRA_CFLAGSto CFLAGS xen/riscv: add explicit check that .got{.plt} is emptyAcked-by Andrew Cooper <[email protected]>
I'm sorry, I failed to apply this ack while committing.
Jan
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Andrew Cooper
Quoted 3 lines · Oleksii Kurochko
Oleksii Kurochko (2):
xen/riscv: addEMBEDDED_EXTRA_CFLAGSto CFLAGS xen/riscv: add explicit check that .got{.plt} is emptyAcked-by Andrew Cooper <[email protected]>I'm sorry, I failed to apply this ack while committing.
Oh well. The important thing is that it's in now.
~Andrew
Quoted 7 lines · Oleksii Kurochko
Oleksii Kurochko (2):
xen/riscv: addEMBEDDED_EXTRA_CFLAGSto CFLAGS xen/riscv: add explicit check that .got{.plt} is emptyxen/arch/riscv/arch.mk | 2 ++ xen/arch/riscv/xen.lds.S | 13 +++++++++++++ 2 files changed, 15 insertions(+)
Just to mention it in case you aren't aware: Hunting down the necessary acks is your responsibility, not one of the committers. You may want to ping Bob and Alistair (unless this response of mine is already enough of a ping). Provided of course the patches still apply as-is ...
Jan
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko
Oleksii Kurochko (2):
xen/riscv: addEMBEDDED_EXTRA_CFLAGSto CFLAGS xen/riscv: add explicit check that .got{.plt} is emptyxen/arch/riscv/arch.mk | 2 ++
xen/arch/riscv/xen.lds.S | 13 +++++++++++++2 files changed, 15 insertions(+)
Quoted 8 lines
Just to mention it in case you aren't aware: Hunting down the necessary acks
is your responsibility, not one of the committers. You may want to ping Bob
and Alistair (unless this response of mine is already enough of a ping).
Provided of course the patches still apply as-is ...
Thanks. I'll take that into account.
I thought the only option I have wait for a response from a maintainer.
~ Oleksii
Quoted 18 lines · Oleksii
Quoted 9 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko
Oleksii Kurochko (2):
xen/riscv: addEMBEDDED_EXTRA_CFLAGSto CFLAGS xen/riscv: add explicit check that .got{.plt} is emptyxen/arch/riscv/arch.mk | 2 ++
xen/arch/riscv/xen.lds.S | 13 +++++++++++++2 files changed, 15 insertions(+)Quoted 8 lines
Just to mention it in case you aren't aware: Hunting down the necessary acks
is your responsibility, not one of the committers. You may want to ping Bob
and Alistair (unless this response of mine is already enough of a ping).
Provided of course the patches still apply as-is ...
Quoted 3 lines
Thanks. I'll take that into account.
I thought the only option I have wait for a response from a maintainer.
Well, in principle yes. But pinging is appropriate after a reasonable amount of time (rule of thumb: a week, maybe two, depending on e.g. complexity).
Jan