<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - GlobalAlias with non-zero offsets and public linkage end of with wrong size"
   href="https://bugs.llvm.org/show_bug.cgi?id=38794">38794</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GlobalAlias with non-zero offsets and public linkage end of with wrong size
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>daphnediane@mac.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I've run into the case where global aliases are not getting the right symbol
sizes in object files.

Example:

 ...
 %global.type = type <{ [7934 x i16] }>
 @global = linkonce_odr global %global.type zeroinitializer, align 4
 @my_alias = alias [1024 x i16], bitcast (i32* getelementptr inbounds (i32,
i32* bitcast (%global.type* @global to i32*), i32 512) to [1024 x i16]*)
 ...

 nm -S file.o
 ...
 00000000 00003dfc V global
 00000800 00003dfc B my_alias
 ...

Location of bug appears to be llvm::AsmPrinter::emitGlobalIndirectSymbol which
seems to have a special case that ignores sizes of aliases but doesn't consider
non-zero offsets. Note because the size is the full size of the base symbol,
this means that the alias symbol appears to go beyond the base symbol in the
section.

Test in question from llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:
   if (auto *GA = dyn_cast<GlobalAlias>(&GIS)) {
     // If the aliasee does not correspond to a symbol in the output, i.e. the
     // alias is not of an object or the aliased object is private, then set
the
     // size of the alias symbol from the type of the alias. We don't do this
in
     // other situations as the alias and aliasee having differing types but
same
     // size may be intentional.
     const GlobalObject *BaseObject = GA->getBaseObject();
     if (MAI->hasDotTypeDotSizeDirective() && GA->getValueType()->isSized() &&
         (!BaseObject || BaseObject->hasPrivateLinkage())) {
       const DataLayout &DL = M.getDataLayout();
       uint64_t Size = DL.getTypeAllocSize(GA->getValueType());
       OutStreamer->emitELFSize(Name, MCConstantExpr::create(Size,
OutContext));
     }
   }</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>