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]
Other format: [Raw text]

Re: About bfd (Binary File Descriptor)


libra <mr924352@cs.nthu.edu.tw> writes:

> After assembling,it will prodece an object file(assume that it not yet linked 
> by linker to become an executable file).In this stage, there must be some 
> information to be wrote to the object file inclde the target file format like
> elf32-littlearm (ex:arm),header, section and so on.
> 
> My question is :
> There must be some place where the program (assembler) to set the file format 
> information in the object file(*.o),and where the program (simulator in gdb) 
> to check the file format to determin this file format is recognized or not.  

Are you asking there in the source code this information is set and
recognized?

The assembler writes out the ELF file header in
elf_write_shdrs_and_ehdr() in bfd/elfcode.h.  The information is
mostly set up in prep_headers() in bfd/elf.c.  Specifically,
    i_ehdrp->e_machine = bed->elf_machine_code;
sets the field in the ELF header which encodes the processor.  The
assembler picks the ELF backend (bed in the above line) by calling
bfd_openw with an appropriate BFD target string.  The target string is
set by defining the macro TARGET_FORMAT in gas/config/tc-*.h.  Many of
those files will use #ifdef OBJ_ELF when setting the target string for
an ELF object file.

The simulator checks the format via a call to bfd_get_format() which
winds up calling elf_object_p() in bfd/elfcode.h.  bfd/elfcode.h is
compiled once for each supported ELF target, by files such as
bfd/elf32-i386.c.  elf_object_p() checks whether the object file
matches the architecture set by the macro ELF_MACHINE_CODE in files
like bfd/elf32-i386.c.

If that doesn't answer your question, then please try again.  Since I
am having trouble understanding you, please give an example of the
type of answer which you find to be acceptable.

Ian


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