<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Dec 12, 2016 19:57, "Petr Hosek" <<a href="mailto:phosek@google.com">phosek@google.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div class="quoted-text"><div dir="ltr">On Mon, Dec 12, 2016 at 7:12 PM Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But as a quick experiment, a single file with just<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
.global a<br class="m_-6539913295874571570gmail_msg">
.hidden a<br class="m_-6539913295874571570gmail_msg">
a = 42<br class="m_-6539913295874571570gmail_msg">
.quad a<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
has no relocations at all, with both mc and gas. That means that the<br class="m_-6539913295874571570gmail_msg">
.quad is always 42. On the other hand, the file has<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
 000000000000002a     0 NOTYPE  GLOBAL HIDDEN   ABS a<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
which is contradictory if ABS means image relative. Is that a bug in gas<br class="m_-6539913295874571570gmail_msg">
and mc?<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
If we now use two files, one with<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
        .quad a<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
and another with<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
        .global a<br class="m_-6539913295874571570gmail_msg">
        .hidden a<br class="m_-6539913295874571570gmail_msg">
        a = 42<br class="m_-6539913295874571570gmail_msg">
<br class="m_-6539913295874571570gmail_msg">
gold will produce a file with no relocations. BFD will produce a<br class="m_-6539913295874571570gmail_msg">
R_X86_64_RELATIVE, but it is the odd one here.<br class="m_-6539913295874571570gmail_msg"></blockquote><div><br></div></div><div>You don't need a dynamic relocation in this case because the symbol is hidden (which is the same as if it was local) as the address can be can be computed statically at link time (relative to the image base). If you remove .hidden, then both gas and mc generate relocation as expected because now the address cannot be determined at link time.</div></div></div>
</blockquote></div><div class="gmail_extra" dir="auto"><br></div>I think Rafael's point is that if a is image relative it would require a relative relocation to adjust the reference in the first file to the image base. Since bfd is emitting the relative relocation and gold isn't, that means that bfd is treating a as image relative and gold is treating it as absolute.</div></div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">Peter</div></div>