Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think I may have figured out the answer to my own question. I'm not sure I'm right, but it's the first explanation I've been able to think of that actually makes sense. What made me rethink things was <a href="http://sourceware.org/binutils/docs-2.21/ld/Expression-Section.html#Expression-Section" rel="noreferrer" title="this page of the documentation">this page of the documentation</a>. Particularly this quote:</p> <blockquote> <p>Addresses and symbols may be section relative, or absolute. A section relative symbol is relocatable. If you request relocatable output using the `-r' option, a further link operation may change the value of a section relative symbol. On the other hand, an absolute symbol will retain the same value throughout any further link operations.</p> </blockquote> <p>and this quote:</p> <blockquote> <p>You can use the builtin function ABSOLUTE to force an expression to be absolute when it would otherwise be relative. For example, to create an absolute symbol set to the address of the end of the output section <code>.data</code>:</p> <pre><code> SECTIONS { .data : { *(.data) _edata = ABSOLUTE(.); } } </code></pre> <p>If <code>ABSOLUTE</code> were not used, <code>_edata</code> would be relative to the <code>.data</code> section.</p> </blockquote> <p>I had read them before, but this time I saw them from a new perspective.</p> <p>So I think my misinterpretation was thinking that a symbol, when assigned a relative byte offset address, is simply set to the value of that offset while the base address information is lost.</p> <p>That was based on this quote from my original question:</p> <blockquote> <p>Note: . actually refers to the byte offset from the start of the current containing object. Normally this is the SECTIONS statement, whose start address is 0, hence . can be used as an absolute address. If . is used inside a section description however, it refers to the byte offset from the start of that section, not an absolute address.</p> </blockquote> <p>Instead what I now understand to be happening is that the base address information is not lost. The symbol does not simply get assigned the value of the offset from the base address. The symbol will still eventually resolves to an absolute address, but only when there's no chance its base address can change.</p> <p>So where I thought that something like <code>__stack_start__ = . ;</code> should have to be changed to <code>__stack_start__ = ABSOLUTE(.) ;</code>, which does work, I now think it is unnecessary. What's more, I understand from the first quote in this response that you can relink an ELF file?</p> <p>So if I used <code>__stack_start__ = ABSOLUTE(.) ;</code>, ran the linker script to create the ELF executable, then tried to relink it and moved the .stack section somewhere else, the <code>__stack_start__</code> symbol would still be pointing to the same absolute address from the first link, and thus be incorrect.</p> <p>This is probably hard to follow, but I've written it as articulately as I could. I suspect I've got close to the right idea, but I still need someone who actually knows about this stuff to confirm or deny this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload