This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug: Wrong architecture with elf32-sh




Dear folks,

When I link an binary and write the output as elf32-sh, i get the wrong=

architecture "sh4"!!!

My application scenario:

* I have a plain object file "image" for sh3 in a binary format.
* I link it to assign an entry point:  sh-elf-ld -T ldscript --section-=
start
.data=3D0x100 --entry=3D0x100c --oformat elf32-sh -o tester -b binary i=
mage
* doing sh-elf-objdump -x tester reports architecture "sh4"
* doing sh-elf-readelf reports "Flags =3D 0"
* starting gdb fails with the message : sh4 unsupported architecture
* I tried to set the output architecture to "sh" or "sh4" with "ld -A" =
and
"OUTPUT_ARCH" but both failed

I found the reason for that unexpected behaviour in the file "bfd/elf32=
-sh.c"

The elf data structure offers two ways for saving the architecture info=
rmation:
* elf_elfheader(bfd)->e_flags
* bfd->arch_info->arch / bfd->arch_info->mach

When reading a bfd-file, e_flags is set from the file. arch/mach is the=
n
initialized from e_flags by sh_elf_set_match_from_flags(bfd)
When setting the architecture (e.g. with *_set_arch_*() ) arch/mach bec=
omes
inconsistent to e_flags!!!!
When writing a bfd-file, arch/mach are no longer considered but lost. O=
nly
e_flags is written to the file.
Thus any modification of arch/mach gets lost :-(

In other targets (e.g. elf32-sparc.c) I found, that e_flags is only con=
sulted
once during initialization. When writing the output, e_flags is regener=
ated from
arch/mach.

The second reason for the strange behavior is:

e_flags=3D0 signals an unknown architecture. sh_elf_set_match_from_flag=
s(bfd) maps
this to "sh4". I=B4m not sure that this is a useful behaviour. I would =
prefer
mapping it to "sh3". That is more consistent to the macro EF_SH_MERGE_M=
ACH in
include/els/sh.h


Unfortunatelly, I don=B4t have the required deep understandiung of BFD =
to deliver
a patch.

If somebody knows help or con deliver me a patch or at least is able to=
 fix this
bug with the next release of binutilities, than please to not hesitate =
to
contact me: dpetras@elsa.de

Kind regards,

     Dietmar





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]