Re: GCC Fedora - relocation truncated to fit: R_X86_64_32S against `.rodata'

2022-12-20 Thread Daniel P . Berrangé
On Tue, Dec 20, 2022 at 02:49:48PM +0100, Florian Weimer wrote:
> * Daniel P. Berrangé:
> 
> > One notable thing is Ubuntu's use of --enable-default-pie. Some Google
> > links also suggested -fPIC as a possible solution to my error, so I
> > tried modifying the build system to add -fPIC to CFLAGS/LDFLAGS, but
> > that merely gave me a differrent set of errors :-(
> 
> Have you tried building with -fPIE?  Why jump straight to -fPIC?

I have not tried -fPIE, I just blindly went to -fPIC out of
habit.

> With -fPIE, the mapping address does not matter to the compiler (so no
> absolute R_X86_64_32S relocations), and external calls should stop using
> the GOT, too (so no more relaxation issues).

Thanks for explaining, I've now confirmed that if I get -fPIE
added in the right places, it successfully builds.


With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|
___
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue


Re: GCC Fedora - relocation truncated to fit: R_X86_64_32S against `.rodata'

2022-12-20 Thread Florian Weimer
* Daniel P. Berrangé:

> One notable thing is Ubuntu's use of --enable-default-pie. Some Google
> links also suggested -fPIC as a possible solution to my error, so I
> tried modifying the build system to add -fPIC to CFLAGS/LDFLAGS, but
> that merely gave me a differrent set of errors :-(

Have you tried building with -fPIE?  Why jump straight to -fPIC?

With -fPIE, the mapping address does not matter to the compiler (so no
absolute R_X86_64_32S relocations), and external calls should stop using
the GOT, too (so no more relaxation issues).

Thanks,
Florian
___
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue


Re: GCC Fedora - relocation truncated to fit: R_X86_64_32S against `.rodata'

2022-12-20 Thread Jakub Jelinek
On Tue, Dec 20, 2022 at 01:49:00PM +0100, Jakub Jelinek wrote:
> On Tue, Dec 20, 2022 at 12:12:42PM +, Daniel P. Berrangé wrote:
> > For KVM AMD SEV-SNP virtualization we're trying to get SVSM guest
> > firmware built on Fedora.
> > 
> >   https://github.com/svsm-vtpm/linux-svsm
> > 
> > It builds successfully on Ubuntu 22.04 (gcc 11.3.0) which is what upstream
> > uses as their primary dev platform. On Fedora 37 (gcc 12.2.1) though, we're
> > getting errors at the final link stage. To eliminate version as a factor,
> > I also tried Fedora 35 with gcc 11.3.1 and got the same errors:
> > 
> > gcc -m64 -nostdlib -Wl,-Tsrc/start/svsm.lds -Wl,--build-id=none -o 
> > svsm.bin.elf src/start/start.o 
> > target/x86_64-unknown-none/debug/liblinux_svsm.a -Wl,--start-group 
> > ./external/build/lib/libtpm.a ./external/build/lib/libplatform.a 
> > ./external/build/lib/libwolfssl.a ./external/build/lib/libcrt.a 
> > ./external/build/lib/libm.a -Wl,--end-group
> > ./external/build/lib/libwolfssl.a(src_libwolfssl_la-sha256.o): in function 
> > `Transform_Sha256':
> > sha256.c:(.text+0xba): relocation truncated to fit: R_X86_64_32 against 
> > `.rodata'
> > ./external/build/lib/libwolfssl.a(src_libwolfssl_la-aes.o): in function 
> > `wc_AesEncrypt':
> > aes.c:(.text+0x50): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0x68): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0x7e): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0x8c): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0x9e): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0xa9): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0xc5): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0xd3): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0xe9): relocation truncated to fit: R_X86_64_32S against 
> > `.rodata'
> > aes.c:(.text+0xf8): additional relocation overflows omitted from the output
> > collect2: error: ld returned 1 exit status
> > make: *** [Makefile:54: svsm.bin.elf] Error 1
> 
> That would mean either that your text + data segment are larger than 2GB, or
> src/start/svsm.lds you are using places the sections somewhere high in the
> address space, incompatible with the x86-64 default -mcmodel=small.
> Ubuntu defaults to -fpie -pie like we use in Fedora when hardening isn't
> disabled through specs from redhat-rpm-config, so it uses a different
> code model (small pic).
> You can build stuff with -fpie and link with -pie if you want, or
> -mcmodel=medium or -mcmodel=large etc., depends really on what 
> src/start/svsm.lds
> is doing and how large the binary is.
> As documented:
> '-mcmodel=small'
>  Generate code for the small code model: the program and its symbols
>  must be linked in the lower 2 GB of the address space.  Pointers
>  are 64 bits.  Programs can be statically or dynamically linked.
>  This is the default code model.
> 
> '-mcmodel=medium'
>  Generate code for the medium model: the program is linked in the
>  lower 2 GB of the address space.  Small symbols are also placed
>  there.  Symbols with sizes larger than '-mlarge-data-threshold' are
>  put into large data or BSS sections and can be located above 2GB.
>  Programs can be statically or dynamically linked.
> 
> '-mcmodel=large'
>  Generate code for the large model.  This model makes no assumptions
>  about addresses and sizes of sections.
> etc.

The linker script has:
SECTIONS
{
. = SVSM_GPA_LDS;
and
#ifndef SVSM_GPA_LDS
#define SVSM_GPA_LDS0x80
#endif /* SVSM_GPA_LDS */

So, this is indeed incompatible with both small and medium code models,
so everything that is linked into that binary should be compiled with
-mcmodel=large and pay the code performance price for that.

Jakub
___
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue


Re: GCC Fedora - relocation truncated to fit: R_X86_64_32S against `.rodata'

2022-12-20 Thread Jakub Jelinek
On Tue, Dec 20, 2022 at 12:12:42PM +, Daniel P. Berrangé wrote:
> For KVM AMD SEV-SNP virtualization we're trying to get SVSM guest
> firmware built on Fedora.
> 
>   https://github.com/svsm-vtpm/linux-svsm
> 
> It builds successfully on Ubuntu 22.04 (gcc 11.3.0) which is what upstream
> uses as their primary dev platform. On Fedora 37 (gcc 12.2.1) though, we're
> getting errors at the final link stage. To eliminate version as a factor,
> I also tried Fedora 35 with gcc 11.3.1 and got the same errors:
> 
> gcc -m64 -nostdlib -Wl,-Tsrc/start/svsm.lds -Wl,--build-id=none -o 
> svsm.bin.elf src/start/start.o 
> target/x86_64-unknown-none/debug/liblinux_svsm.a -Wl,--start-group 
> ./external/build/lib/libtpm.a ./external/build/lib/libplatform.a 
> ./external/build/lib/libwolfssl.a ./external/build/lib/libcrt.a 
> ./external/build/lib/libm.a -Wl,--end-group
> ./external/build/lib/libwolfssl.a(src_libwolfssl_la-sha256.o): in function 
> `Transform_Sha256':
> sha256.c:(.text+0xba): relocation truncated to fit: R_X86_64_32 against 
> `.rodata'
> ./external/build/lib/libwolfssl.a(src_libwolfssl_la-aes.o): in function 
> `wc_AesEncrypt':
> aes.c:(.text+0x50): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0x68): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0x7e): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0x8c): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0x9e): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0xa9): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0xc5): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0xd3): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0xe9): relocation truncated to fit: R_X86_64_32S against 
> `.rodata'
> aes.c:(.text+0xf8): additional relocation overflows omitted from the output
> collect2: error: ld returned 1 exit status
> make: *** [Makefile:54: svsm.bin.elf] Error 1

That would mean either that your text + data segment are larger than 2GB, or
src/start/svsm.lds you are using places the sections somewhere high in the
address space, incompatible with the x86-64 default -mcmodel=small.
Ubuntu defaults to -fpie -pie like we use in Fedora when hardening isn't
disabled through specs from redhat-rpm-config, so it uses a different
code model (small pic).
You can build stuff with -fpie and link with -pie if you want, or
-mcmodel=medium or -mcmodel=large etc., depends really on what 
src/start/svsm.lds
is doing and how large the binary is.
As documented:
'-mcmodel=small'
 Generate code for the small code model: the program and its symbols
 must be linked in the lower 2 GB of the address space.  Pointers
 are 64 bits.  Programs can be statically or dynamically linked.
 This is the default code model.

'-mcmodel=medium'
 Generate code for the medium model: the program is linked in the
 lower 2 GB of the address space.  Small symbols are also placed
 there.  Symbols with sizes larger than '-mlarge-data-threshold' are
 put into large data or BSS sections and can be located above 2GB.
 Programs can be statically or dynamically linked.

'-mcmodel=large'
 Generate code for the large model.  This model makes no assumptions
 about addresses and sizes of sections.
etc.

Jakub
___
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue


Re: GCC Fedora - relocation truncated to fit: R_X86_64_32S against `.rodata'

2022-12-20 Thread Sérgio Basto
On Tue, 2022-12-20 at 12:12 +, Daniel P. Berrangé wrote:
> gcc -m64 -nostdlib -Wl,-Tsrc/start/svsm.lds -Wl,--build-id=none -o
> svsm.bin.elf src/start/start.o target/x86_64-unknown-
> none/debug/liblinux_svsm.a -Wl,--start-group
> ./external/build/lib/libtpm.a ./external/build/lib/libplatform.a
> ./external/build/lib/libwolfssl.a ./external/build/lib/libcrt.a
> ./external/build/lib/libm.a -Wl,--end-group

https://stackoverflow.com/questions/19768267/relocation-r-x86-64-32s-against-linking-error/38579792#38579792
-- 
Sérgio M. B.
___
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue


GCC Fedora - relocation truncated to fit: R_X86_64_32S against `.rodata'

2022-12-20 Thread Daniel P . Berrangé
For KVM AMD SEV-SNP virtualization we're trying to get SVSM guest
firmware built on Fedora.

  https://github.com/svsm-vtpm/linux-svsm

It builds successfully on Ubuntu 22.04 (gcc 11.3.0) which is what upstream
uses as their primary dev platform. On Fedora 37 (gcc 12.2.1) though, we're
getting errors at the final link stage. To eliminate version as a factor,
I also tried Fedora 35 with gcc 11.3.1 and got the same errors:

gcc -m64 -nostdlib -Wl,-Tsrc/start/svsm.lds -Wl,--build-id=none -o svsm.bin.elf 
src/start/start.o target/x86_64-unknown-none/debug/liblinux_svsm.a 
-Wl,--start-group ./external/build/lib/libtpm.a 
./external/build/lib/libplatform.a ./external/build/lib/libwolfssl.a 
./external/build/lib/libcrt.a ./external/build/lib/libm.a -Wl,--end-group
./external/build/lib/libwolfssl.a(src_libwolfssl_la-sha256.o): in function 
`Transform_Sha256':
sha256.c:(.text+0xba): relocation truncated to fit: R_X86_64_32 against 
`.rodata'
./external/build/lib/libwolfssl.a(src_libwolfssl_la-aes.o): in function 
`wc_AesEncrypt':
aes.c:(.text+0x50): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0x68): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0x7e): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0x8c): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0x9e): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0xa9): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0xc5): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0xd3): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0xe9): relocation truncated to fit: R_X86_64_32S against `.rodata'
aes.c:(.text+0xf8): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
make: *** [Makefile:54: svsm.bin.elf] Error 1


I'm guessing there must be some difference in GCC defaults that is
affecting things

The Ubuntu build specs are

# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs 
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr 
--with-gcc-major-version-only --program-suffix=-11 
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id 
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix 
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib 
--enable-libphobos-checking=release --with-target-system-zlib=auto 
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet 
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 
--enable-multilib --with-tune=generic 
--enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr
 --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu 
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) 


While Fedora build specs are


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap 
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared 
--enable-threads=posix --enable-checking=release --enable-multilib 
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions 
--enable-gnu-unique-object --enable-linker-build-id 
--with-gcc-major-version-only --enable-libstdcxx-backtrace 
--with-linker-hash-style=gnu --enable-plugin --enable-initfini-array 
--with-isl=/builddir/build/BUILD/gcc-12.2.1-20221121/obj-x86_64-redhat-linux/isl-install
 --enable-offload-targets=nvptx-none --without-cuda-driver 
--enable-offload-defaulted --enable-gnu-indirect-function --enable-cet 
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux 
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.1 20221121 (Red Hat 12.2.1-4) (GCC) 


One notable thing is Ubuntu's use of --enable-default-pie.