[llvm] f6d209b - [AIX][XCOFF] error on emit symbol visibility for XCOFF object file

David Tenty via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 16:22:52 PDT 2022


Author: David Tenty
Date: 2022-04-26T19:22:44-04:00
New Revision: f6d209b3ec4c923f20388e3380099b2b0707f786

URL: https://github.com/llvm/llvm-project/commit/f6d209b3ec4c923f20388e3380099b2b0707f786
DIFF: https://github.com/llvm/llvm-project/commit/f6d209b3ec4c923f20388e3380099b2b0707f786.diff

LOG: [AIX][XCOFF] error on emit symbol visibility for XCOFF object file

This is a follow on to the revert of D84265 to add an error if we'd need
to write a non-zero visibility type in the xcoff object file. We can't
currently do that because we lack the auxilary header to interpret the
bits in XCOFF32. This is important because visibility is being enabled
in the assembly writing path, and without this error the visibility
could be silently ignored.

Differential Revision: https://reviews.llvm.org/D124392

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCSectionXCOFF.h
    llvm/lib/MC/XCOFFObjectWriter.cpp
    llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h
index f83e083b85e55..db18566a44a34 100644
--- a/llvm/include/llvm/MC/MCSectionXCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionXCOFF.h
@@ -95,6 +95,9 @@ class MCSectionXCOFF final : public MCSection {
   XCOFF::StorageClass getStorageClass() const {
     return QualName->getStorageClass();
   }
+  XCOFF::VisibilityType getVisibilityType() const {
+    return QualName->getVisibilityType();
+  }
   XCOFF::SymbolType getCSectType() const {
     assert(isCsect() && "Only csect section has symbol type property!");
     return CsectProp->Type;

diff  --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index ea3bad4e31145..76cfc85c87148 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -66,6 +66,10 @@ struct Symbol {
   const MCSymbolXCOFF *const MCSym;
   uint32_t SymbolTableIndex;
 
+  XCOFF::VisibilityType getVisibilityType() const {
+    return MCSym->getVisibilityType();
+  }
+
   XCOFF::StorageClass getStorageClass() const {
     return MCSym->getStorageClass();
   }
@@ -84,6 +88,9 @@ struct XCOFFSection {
   SmallVector<Symbol, 1> Syms;
   SmallVector<XCOFFRelocation, 1> Relocations;
   StringRef getSymbolTableName() const { return MCSec->getSymbolTableName(); }
+  XCOFF::VisibilityType getVisibilityType() const {
+    return MCSec->getVisibilityType();
+  }
   XCOFFSection(const MCSectionXCOFF *MCSec)
       : MCSec(MCSec), SymbolTableIndex(-1), Address(-1), Size(0) {}
 };
@@ -670,7 +677,8 @@ void XCOFFObjectWriter::writeSymbolEntry(StringRef SymbolName, uint32_t Value,
   // table entries for a detailed description. Since we don't yet support
   // visibility, and all other bits are either optionally set or reserved, this
   // is always zero.
-  // TODO FIXME How to assert a symbol's visibilty is default?
+  if (SymbolType != 0)
+    report_fatal_error("Emitting non-zero visibilities is not supported yet.");
   // TODO Set the function indicator (bit 10, 0x0020) for functions
   // when debugging is enabled.
   W.write<uint16_t>(SymbolType);
@@ -706,7 +714,7 @@ void XCOFFObjectWriter::writeSymbolEntryForCsectMemberLabel(
 
   writeSymbolEntry(SymbolRef.getSymbolTableName(),
                    CSectionRef.Address + SymbolOffset, SectionIndex,
-                   /*SymbolType=*/0, SymbolRef.getStorageClass());
+                   SymbolRef.getVisibilityType(), SymbolRef.getStorageClass());
 
   writeSymbolAuxCsectEntry(CSectionRef.SymbolTableIndex, XCOFF::XTY_LD,
                            CSectionRef.MCSec->getMappingClass());
@@ -726,7 +734,7 @@ void XCOFFObjectWriter::writeSymbolEntryForControlSection(
     const XCOFFSection &CSectionRef, int16_t SectionIndex,
     XCOFF::StorageClass StorageClass) {
   writeSymbolEntry(CSectionRef.getSymbolTableName(), CSectionRef.Address,
-                   SectionIndex, /*SymbolType=*/0, StorageClass);
+                   SectionIndex, CSectionRef.getVisibilityType(), StorageClass);
 
   writeSymbolAuxCsectEntry(CSectionRef.Size, getEncodedType(CSectionRef.MCSec),
                            CSectionRef.MCSec->getMappingClass());

diff  --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll
index 1875170addc2e..77e76040b08d3 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-visibility.ll
@@ -3,6 +3,18 @@
 ; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr4 -mattr=-altivec -data-sections=false < %s |\
 ; RUN:   FileCheck %s
 
+; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff \
+; RUN:     -filetype=obj -o %t.o < %s 2>&1 | \
+; RUN:   FileCheck --check-prefix=XCOFF32 %s
+; XCOFF32: LLVM ERROR: Emitting non-zero visibilities is not supported yet.
+
+; RUN: not --crash llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff \
+; RUN:     -filetype=obj -o %t.o 2>&1 < %s 2>&1 | \
+; RUN:   FileCheck --check-prefix=XCOFF64 %s
+; FIXME: This should check for the visibility error, but we actually fail before
+; that due to unimplemented relocations.
+; XCOFF64: LLVM ERROR: Unimplemented fixup kind.
+
 @b =  global i32 0, align 4
 @b_h = hidden global i32 0, align 4
 


        


More information about the llvm-commits mailing list