[llvm-bugs] [Bug 38794] New: GlobalAlias with non-zero offsets and public linkage end of with wrong size

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 31 12:03:31 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38794

            Bug ID: 38794
           Summary: GlobalAlias with non-zero offsets and public linkage
                    end of with wrong size
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: daphnediane at mac.com
                CC: llvm-bugs at lists.llvm.org

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));
     }
   }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180831/97cbb3dd/attachment-0001.html>


More information about the llvm-bugs mailing list