Collectives on Stack Overflow. Learn more. Asked 10 years, 3 months ago. Active 6 years, 2 months ago. Viewed 5k times. Improve this question. Griwes Griwes 8, 2 2 gold badges 42 42 silver badges 70 70 bronze badges. Your question now makes less sense, not more I want to be able to compile my programs using GNU toolchain, but executable should be generated in format defined by me. OK, I understand you now. Git stats 31 commits. Failed to load latest commit information. View code. We can either pass a filename or a file descriptor and they will be used in the same way.
We'll obtain instruction address, size, type and disassembly in text format. Resources Readme. Releases No releases published. Packages 0 No packages published. Information can be lost during output.
The output formats supported by BFD do not provide identical facilities, and information which can be described in one form has nowhere to go in another format. One example of this is alignment information in b. There is nowhere in an a. The linker will still use the alignment information internally, so the link is performed correctly.
Another example is COFF section names. COFF files may contain an unlimited number of sections, each one with a textual section name. If the target of the link is a format which does not have many sections e. You can circumvent this problem by describing the desired input-to-output section mapping with the linker command language. Information can be lost during canonicalization. The BFD internal canonical form of the external formats is not exhaustive; there are structures in input formats for which there is no direct representation internally.
This means that the BFD back ends cannot maintain all possible data richness through the transformation between external to internal and back to external formats. This limitation is only a problem when an application reads one format and writes another. Each BFD back end is responsible for maintaining as much data as possible, and the internal BFD canonical form has structures which are opaque to the BFD core, and exported only to the back ends.
When a file is read in one format, the canonical form is generated for BFD and the application. At the same time, the back end saves away any information which may otherwise be lost. If the data is then written back in the same format, the back end routine will be able to use the canonical form provided by the BFD core as well as the information it prepared earlier.
Since there is a great deal of commonality between back ends, there is no information lost when linking or copying big endian COFF to little endian COFF, or a. When a mixture of formats is linked, the information is only lost from the files whose format differs from the destination. The greatest potential for loss of information occurs when there is the least overlap between the information provided by the source format, that stored by the canonical format, and that needed by the destination format.
A brief description of the canonical form may help you understand which kinds of data you can count on preserving across conversions. Here is the structure that defines the type bfd. It contains the major data about the file and pointers to the rest of the data. Most BFD functions return nonzero on success check their individual documentation for precise semantics. If message is non-NULL and non-empty, the error string printed is preceded by message , a colon, and a space. It is followed by a newline.
Some BFD functions want to print messages describing the problem. They call a BFD error handler function. This function may be overriden by the program. Returns the previous function. This is printed before the error message followed by a colon and space. The string must not be changed after it is passed to this function.
If an error occurs, return Returns the number of relocs, or -1 on error. The argument abfd is ignored. Returns Returns true on success, false otherwise. The initial motivation for, and use of, this routine is not so we can get the exact size of the object the BFD applies to, since that might not be generally possible archive members for example. It would be ideal if someone could eventually modify it so that such results were guaranteed.
If an application tries to read what it thinks is one of these string tables, without some way to validate the size, and for some reason the size is wrong byte swapping error, wrong location for the string table, etc. This function at least allows us to answer the quesion, "is the size reasonable?
This is typically set by the -G argument to the compiler, assembler or linker. Though without as many bells and whistles as strtoul.
The expression is assumed to be unsigned i. If given a base , it is used as the base for conversion. A base of 0 causes the function to interpret the string in hex if a leading "0x" or "0X" is found, otherwise in octal if a leading zero is found, otherwise in decimal. Return true on success, false on error.
Possible error returns are:. There is one obstack per open BFD file, into which the current state is stored. When a BFD is closed, the obstack is deleted, and so everything which has been allocated by BFD for the closing file is thrown away. The general rule is to not close a BFD until all operations dependent upon data from the BFD have been completed, or all the data from within the file has been copied.
This could be used to select the greediest open BFD, close it to reclaim the memory, perform some operation and reopen the BFD again, to get a fresh copy of the data structures. The raw data contained within a BFD is maintained through the section abstraction. A single BFD may have any number of sections. It keeps hold of them by pointing to the first; each one points to the next in the list.
Each section has a name which describes the section in the outside world--for example, a. Names need not be unique; for example a COFF file may have several sections named. Sometimes a BFD will contain more than the "natural" number of sections. The raw data is not necessarily read in when the section descriptor is created. Other back ends may read in all the data at once. For example, an S-record file has to be read once to determine the size of the data.
An IEEE file doesn't contain raw data in sections, but data and relocation expressions intermixed, so the data area has to be parsed to get out the data and relocations.
To write a new object style BFD, the various sections to be written have to be created. Any program that creates or combines sections e. The output section structure can be considered a filter for the input section: the output section determines the vma of the output data and the name, but the input section determines the offset into the output section of the data to be written.
These are much like the fixups in gas. The compiler creates code which is as big as necessary to make it work without relaxing, and the user can select whether to relax. Sometimes relaxing takes a lot of time. See section Sections , for more information. An attempt to create a section with a name which is already in use returns its pointer without changing the section chain. Create a new section even if there is already a section with that name.
The function will be called as if by. If the operation is ok, then true is returned, else false. The data is written to the output section starting at offset offset for count bytes. Normally true is returned, else false. The data is read at an offset of offset from the start of the input section, and is read for count bytes. If no errors occur, true is returned, else false. BFD tries to maintain as much symbol information as it can when it moves information from file to file.
BFD passes information to applications though the asymbol structure. When the application requests the symbol table, BFD reads the table in the native form and translates parts of it into the internal format.
To maintain more than the information passed to applications, some targets keep some information "behind the scenes" in a structure only the particular back end knows about. For example, the coff back end keeps the original symbol table structure as well as the canonical structure when a BFD is read in. On output, the coff back end can reconstruct the output symbol table so that no information is lost, even information unique to coff which BFD doesn't know or understand. If a coff symbol table were read, but were written through an a.
The symbol table of a BFD is not necessarily read in until a canonicalize request is made. Then the BFD back end fills in a table provided by the application with pointers to the canonical information. To output symbols, the application provides BFD with a table of pointers to pointers to asymbol s.
This allows applications like the linker to output a symbol as it was read, since the "behind the scenes" information will be still available.
There are two stages to reading a symbol table from a BFD: allocating storage, and the actual reading process. This is an excerpt from an application which reads the symbol table:.
Writing of a symbol table is automatic when a BFD open for writing is closed. The application attaches a vector of pointers to pointers to symbols to the BFD being written, and fills in the symbol count. The close and cleanup code reads through the table provided and performs all the necessary operations. Here is an example showing the creation of a symbol table with only one element:. Many formats cannot represent arbitary symbol information; for instance, the a.
A symbol pointing to a section which is not one of. Mini symbols provide read-only access to the symbol table. They use less memory space, but require more time to access. They can be useful for tools like nm or objdump, which may have to handle symbol tables of extremely large executables.
The pointer is allocated using malloc , and should be freed by the caller when it is no longer needed. If there are no symbols in the BFD, then return 0. This just checks whether the name has the form of a local label. Return the actual number of symbol pointers, not including the NULL. This routine is necessary because each back end has private information surrounding the asymbol.
Building your own asymbol and pointing to it will not create the private information, and will cause problems later on. Further details of its use have yet to be worked out. Asked 11 years, 7 months ago. Active 6 years ago. Viewed 2k times. Improve this question. Add a comment.
Active Oldest Votes. Improve this answer.
0コメント