[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/27200] New: Bad RiscV64 ELF header flag using ld -b binary
From: |
bztemail at gmail dot com |
Subject: |
[Bug ld/27200] New: Bad RiscV64 ELF header flag using ld -b binary |
Date: |
Mon, 18 Jan 2021 13:01:57 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=27200
Bug ID: 27200
Summary: Bad RiscV64 ELF header flag using ld -b binary
Product: binutils
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: bztemail at gmail dot com
Target Milestone: ---
Dear binutils developers,
I've found an issue with the latest GNU ld in binutils about generating RiscV64
ELF headers.
ENVIRONMENT
I'm compiling a cross-compilers from the latest version with the following
configure flags (both binutils and gcc):
--enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib
--with-isl --enable-__cxa_atexit \
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-plugin \
--disable-linker-build-id --enable-lto --enable-install-libiberty
--with-linker-hash-style=gnu --with-gnu-ld\
--enable-gnu-indirect-function --disable-multilib --disable-werror
--enable-checking=release --enable-default-pie \
--enable-default-ssp --enable-gnu-unique-object --target=$(ARCH)-elf
(I repeat this with ARCH being x86_64, aarch64 and riscv64.)
I've made the following modification in gcc's configure (but not in binutils)
to enable -fvisibility command line flag, if this matters:
cat configure|sed 's/gcc_cv_as_hidden=no/gcc_cv_as_hidden=yes/'|sed
's/gcc_cv_ld_hidden=no/gcc_cv_ld_hidden=yes/'
PROBLEM DESCRIPTION
Then with the newly compiled cross-toolchains, I compile a simple C source and
convert a binary into ELF then link them together:
$(ARCH)-elf-gcc -Wall -fpic -ffreestanding -fno-stack-protector -nostdinc
-nostdlib -I../../dist/ -c kernel.c -o kernel.o
$(ARCH)-elf-ld -r -b binary -o font.o font.psf
$(ARCH)-elf-ld -nostdlib -nostartfiles -T link.ld kernel.o font.o -o
mykernel.$(ARCH).elf
(Full source and Makefile can be found here (small, few Kbytes):
https://gitlab.com/bztsrc/bootboot/-/tree/master/mykernel/c)
The above works for x86_64 and aarch64, but not for riscv64. I'm unable to link
font.o and kernel.o together, because of ELF header mismatch. Full command and
error message:
riscv64-elf-ld -nostdlib -nostartfiles -T link.ld kernel.o font.o -o
mykernel.riscv64.elf
riscv64-elf-ld: font.o: can't link soft-float modules with double-float modules
For gcc (and binutils' as) the byte at file offset 48 (Elf64_Ehdr.e_flags) is 5
(indicating RCV, double-float). But for font.o, which I've created using "ld -b
binary", that is 0 (indicating soft-float). Obviously emulation doesn't matter
here because font.o does not have any text sections, and binutils was compiled
for double-float emulation anyway, so it should save double-float in the ELF
header in the first place. But my biggest problem is, there's no command line
flag to override soft-float with -b binary.
WORKAROUND
To make sure this is the only problem with the ELF header, I've used
riscv64-elf-ld -r -b binary -o font.o font.psf
@echo -ne '\005' | dd conv=notrunc of=font.o bs=1 seek=48
After that I was able to link font.o and kernel.o together without any
problems, and the resulted executable worked as expected.
SUGGESTED SOLUTION
Since both gcc and binutils were compiled with the same configure flags, I
think they should have the same emulation and they should save the same flags
in the ELF headers. Or at a minimum provide an ld command line flag to set the
ELF header flag for "-b binary".
Let me know if you need any more information or tests.
Cheers,
bzt
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug ld/27200] New: Bad RiscV64 ELF header flag using ld -b binary,
bztemail at gmail dot com <=
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, address@hidden, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, bztemail at gmail dot com, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, address@hidden, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, bztemail at gmail dot com, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, bztemail at gmail dot com, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, bztemail at gmail dot com, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, address@hidden, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, bztemail at gmail dot com, 2021/01/18
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, nickc at redhat dot com, 2021/01/19
- [Bug ld/27200] Bad RiscV64 ELF header flag using ld -b binary, nickc at redhat dot com, 2021/01/19