[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v1] xen/riscv: make calculation of stack address PC-relative
On Wed, 2023-03-15 at 08:59 +0100, Jan Beulich wrote: > On 14.03.2023 21:16, Oleksii wrote: > > I checked in Linux binary how 'la' instruction is transformed, and > > it > > looks like it is translated as I expect to auipc/addi pair: > > ffffffe000001066: 00027517 auipc a0,0x27 > > ffffffe00000106a: f9a50513 addi a0,a0,-102 # ffffffe000028000 > > <early_pg_dir> > > > > I checked compiler flags between Xen and Linux. The difference is > > in- > > fno-PIE (Linux also adds -mabi and -march to AFLAGS): > > > > 1. Linux build command of head.S: riscv64-linux-gnu-gcc -Wp,- > > MD,arch/riscv/kernel/.head.o.d -nostdinc -isystem /usr/lib/gcc- > > cross/riscv64-linux-gnu/9/include -I./arch/riscv/include - > > I./arch/riscv/include/generated -I./include - > > I./arch/riscv/include/uapi > > -I./arch/riscv/include/generated/uapi -I./include/uapi - > > I./include/generated/uapi -include ./include/linux/kconfig.h - > > D__KERNEL__ -D__ASSEMBLY__ -fno-PIE -mabi=lp64 -march=rv64imafdc -c > > -o > > arch/riscv/kernel/head.o arch/riscv/kernel/head.S > > > > 2. Xen build command of head.S:riscv64-linux-gnu-gcc -MMD -MP -MF > > arch/riscv/riscv64/.head.o.d -D__ASSEMBLY__ -Wa,--noexecstack - > > DBUILD_ID -fno-strict-aliasing -Wall -Wstrict-prototypes - > > Wdeclaration- > > after-statement -Wno-unused-but-set-variable -Wno-unused-local- > > typedefs > > -O1 -fno-omit-frame-pointer -nostdinc -fno-builtin -fno-common - > > Werror > > -Wredundant-decls -Wno-pointer-arith -Wvla -pipe -D__XEN__ -include > > ./include/xen/config.h -Wa,--strip-local-absolute -g -mabi=lp64 - > > I./include -I./arch/riscv/include -march=rv64gc -mstrict-align - > > mcmodel=medany - -c arch/riscv/riscv64/head.S -o > > arch/riscv/riscv64/head.o > > Looking into why you see different code generated than I: Nothing in > here directs gcc to pass -fpic to gas; in upstream gcc (consistent > from gcc7 through gcc12, which are the versions I've checked; the > actual range may be wider) there is > > #define ASM_SPEC "\ > %(subtarget_asm_debugging_spec) \ > %{" FPIE_OR_FPIC_SPEC ":-fpic} \ > ... > > Can you check whether your gcc passes -fpic to gas even when there's > no -fPIC / -fPIE (or alike) on the gcc command line? I am not sure that I know how to check specifically if -fpic flag passes to gas. Could you please tell me? > Or whether your > gas (unlike upstream's) defaults to PIC mode? (For .S files ASM_SPEC > is all that counts. For .c files gcc is redundantly passing -fpic > along with also emitting ".option pic" or, in the opposite case, it > is omitting -fpic along with emitting ".option nopic".) it looks like it should be by default -fpic because if look 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 > > You gcc may have been configured with --enable-default-pie, while I > know mine hasn't been (simply because that's the default). You are right my gcc is configured 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) So should we pass to CFLAGS and AFLAGS at least for RISC-V -fno-PIE? ~ Oleksii
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |