<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [MC] Clang integrated-as doesn't support local aliases to global variables (GNU as does)."
   href="https://llvm.org/bugs/show_bug.cgi?id=24486">24486</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[MC] Clang integrated-as doesn't support local aliases to global variables (GNU as does).
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>m.ostapenko@partner.samsung.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, rafael.espindola@gmail.com, y.gribov@samsung.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Trying to resolve this
<a href="https://code.google.com/p/address-sanitizer/issues/detail?id=398">https://code.google.com/p/address-sanitizer/issues/detail?id=398</a> issue, I found
out, that clang integrated-as doesn't support local aliases to global variables
(GNU assembler does). Consider the following testcase:

$ cat test.s

    .data
    .global foo
foo:
    .long
bar = foo
    .long    bar

$ clang -c tmp.s && readelf -r tmp.o

Relocation section '.rela.data' at offset 0x90 contains 1 entries:
  Offset          Info           Type           Sym. Value    Sym. Name +
Addend
000000000000  00020000000a R_X86_64_32       0000000000000000 foo + 0

$ gcc -c tmp.s && readelf -r tmp.o

Relocation section '.rela.data' at offset 0x318 contains 1 entries:
  Offset          Info           Type           Sym. Value    Sym. Name +
Addend
000000000000  00020000000a R_X86_64_32       0000000000000000 .data + 0

While GNU as generates relocation for "bar", addressing local .data storage,
clang integrated as addresses it to its aliasee, global variable "foo", that
might be located in completely different place (e.g. when shared library and
executable define the same global variable).

After some investigation, I found out, that the code responsible for Sym. Name
entry in '.rela.data' section located here:

$ cat lib/MC/MCExpr.cpp

bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
                                       const MCAsmLayout *Layout,
                                       const MCFixup *Fixup,
                                       const SectionAddrMap *Addrs,
                                       bool InSet) const {
.........................

  case SymbolRef: {
    const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
    const MCSymbol &Sym = SRE->getSymbol();

    // Evaluate recursively if this is a variable.
    if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None &&
        canExpand(Sym, Asm, InSet)) {
      bool IsMachO = SRE->hasSubsectionsViaSymbols();
      if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
              Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
........................
  } 

Is this the right place to fix the issue? Could someone more familiar with
Clang/LLVM code base help me to cook proper fix?</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>