问题描述:

I would like to output an extra variable (i.e. data block with a symbol pointing to it) from a LD script. This variable would contain either constant values, or the offsets and sizes of various other variables in the same section of the output file. In other words, I would like to create a header from a LD script.

I could probably do this with a custom C file referencing symbols defined in the LD script, but I wonder whether it would not be possible to avoid that extra step and do it directly in the LD script. Is it possible?

网友答案:

Finally found a way in LD's documentation: (http://www.math.utah.edu/docs/info/ld_3.html#SEC17)

BYTE(expression)
SHORT(expression)
LONG(expression)
QUAD(expression)
    By including one of these four statements in a section definition,
    you can explicitly place one, two, four, or eight bytes
    (respectively) at the current address of that section. QUAD is only
    supported when using a 64 bit host or target. Multiple-byte
    quantities are represented in whatever byte order is appropriate for
    the output file format (see section BFD).

Question still opened in case there are better answers.

相关阅读:
Top