1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[XCOFF] Don't emit non-external labels in the symbol table and handle MCSA_LGlobal

Summary:
We need to handle the  MCSA_LGlobal case in emitSymbolAttribute for functions marked internal in the IR so that the
appropriate storage class is emitted on the function descriptor csect.  As part of this we need to make sure that external
labels are not emitted into the symbol table, so we don't emit the descriptor label in the object writing path.

Reviewers: jasonliu, DiggerLin, hubert.reinterpretcast

Reviewed By: jasonliu

Subscribers: Xiangling_L, wuzish, nemanjai, hiraditya, jsji, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74968
This commit is contained in:
David Tenty 2020-02-27 10:43:27 -05:00
parent d1f1b50843
commit ab8ea38971
5 changed files with 58 additions and 97 deletions

View File

@ -10,12 +10,13 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCXCOFFStreamer.h"
#include "llvm/BinaryFormat/XCOFF.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCDirectives.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSymbolXCOFF.h"
#include "llvm/MC/MCXCOFFStreamer.h"
#include "llvm/Support/TargetRegistry.h"
using namespace llvm;
@ -37,6 +38,10 @@ bool MCXCOFFStreamer::emitSymbolAttribute(MCSymbol *Sym,
Symbol->setStorageClass(XCOFF::C_EXT);
Symbol->setExternal(true);
break;
case MCSA_LGlobal:
Symbol->setStorageClass(XCOFF::C_HIDEXT);
Symbol->setExternal(true);
break;
default:
report_fatal_error("Not implemented yet.");
}

View File

@ -353,6 +353,10 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
if (XSym == ContainingCsect->getQualNameSymbol())
continue;
// Only put a label into the symbol table when it is an external label.
if (!XSym->isExternal())
continue;
assert(SectionMap.find(ContainingCsect) != SectionMap.end() &&
"Expected containing csect to exist in map");
// Lookup the containing csect and add the symbol to it.

View File

@ -0,0 +1,38 @@
; RUN: llc -mtriple powerpc-ibm-aix -verify-machineinstrs -mcpu=pwr4 \
; RUN: -filetype=obj -o %t.o < %s
; RUN: llvm-readobj --syms %t.o | FileCheck %s
; RUN: not --crash llc -mtriple powerpc64-ibm-aix -verify-machineinstrs -mcpu=pwr4 \
; RUN: -filetype=obj -o %t.o < %s 2>&1 | FileCheck --check-prefix=64-CHECK %s
define internal i32 @foo() {
ret i32 1
}
; CHECK: Symbol {
; CHECK: Name: .foo
; CHECK-NEXT: Value (RelocatableAddress):
; CHECK-NEXT: Section: .text
; CHECK-NEXT: Type: 0x0
; CHECK-NEXT: StorageClass: C_HIDEXT (0x6B)
; CHECK: Symbol {
; CHECK-NEXT: Index: [[#INDX:]]
; CHECK-NEXT: Name: foo
; CHECK-NEXT: Value (RelocatableAddress):
; CHECK-NEXT: Section: .data
; CHECK-NEXT: Type: 0x0
; CHECK-NEXT: StorageClass: C_HIDEXT (0x6B)
; CHECK-NEXT: NumberOfAuxEntries: 1
; CHECK-NEXT: CSECT Auxiliary Entry {
; CHECK-NEXT: Index: [[#INDX+1]]
; CHECK-NEXT: SectionLen: 12
; CHECK-NEXT: ParameterHashIndex:
; CHECK-NEXT: TypeChkSectNum:
; CHECK-NEXT: SymbolAlignmentLog2:
; CHECK-NEXT: SymbolType: XTY_SD (0x1)
; CHECK-NEXT: StorageMappingClass: XMC_DS (0xA)
; Make sure no label is emitted.
; CHECK-NOT: Name: foo
;64-CHECK: LLVM ERROR: 64-bit XCOFF object files are not supported yet.

View File

@ -52,18 +52,15 @@ entry:
;CHECKOBJ-NEXT: 4: 4e 80 00 20 blr
;CHECKOBJ-NEXT: ...{{[[:space:]] *}}
;CHECKOBJ-NEXT: 00000010 .rodata:
;CHECKOBJ-NEXT: 10: 40 00 00 00 bdnzf 0, .+0
;CHECKOBJ-NEXT: 14: 00 00 00 32 <unknown>
;CHECKOBJ-NEXT: 10: 40 00 00 00
;CHECKOBJ-NEXT: 14: 00 00 00 32
;CHECKOBJ-NEXT: ...{{[[:space:]] *}}
;CHECKOBJ-NEXT: 00000030 .L__const.main.cnst16:
;CHECKOBJ-NEXT: 30: 40 00 00 00 bdnzf 0, .+0
;CHECKOBJ-NEXT: 34: 00 00 00 16 <unknown>
;CHECKOBJ-SAME: 30: 40 00 00 00
;CHECKOBJ-NEXT: 34: 00 00 00 16
;CHECKOBJ-NEXT: ...{{[[:space:]] *}}
;CHECKOBJ-NEXT: 00000040 .L__const.main.cnst8:
;CHECKOBJ-NEXT: 40: 40 00 00 08 bdnzf 0, .+8
;CHECKOBJ-NEXT: 44: 00 00 00 00 <unknown>{{[[:space:]] *}}
;CHECKOBJ-NEXT: 00000048 .L__const.main.cnst4:
;CHECKOBJ-NEXT: 48: 40 08 00 00 bdnzf 8, .+0
;CHECKOBJ-SAME: 40: 40 00 00 08
;CHECKOBJ-NEXT: 44: 00 00 00 00
;CHECKOBJ-NEXT: 48: 40 08 00 00
;CHECKSYM: Symbol {{[{][[:space:]] *}}Index: [[#Index:]]{{[[:space:]] *}}Name: .rodata
@ -84,83 +81,3 @@ entry:
;CHECKSYM-NEXT: StabSectNum: 0x0
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: Symbol {
;CHECKSYM-NEXT: Index: [[#Index+2]]
;CHECKSYM-NEXT: Name: .L__const.main.cnst32
;CHECKSYM-NEXT: Value (RelocatableAddress): 0x10
;CHECKSYM-NEXT: Section: .text
;CHECKSYM-NEXT: Type: 0x0
;CHECKSYM-NEXT: StorageClass: C_HIDEXT (0x6B)
;CHECKSYM-NEXT: NumberOfAuxEntries: 1
;CHECKSYM-NEXT: CSECT Auxiliary Entry {
;CHECKSYM-NEXT: Index: [[#Index+3]]
;CHECKSYM-NEXT: ContainingCsectSymbolIndex: [[#Index]]
;CHECKSYM-NEXT: ParameterHashIndex: 0x0
;CHECKSYM-NEXT: TypeChkSectNum: 0x0
;CHECKSYM-NEXT: SymbolAlignmentLog2: 0
;CHECKSYM-NEXT: SymbolType: XTY_LD (0x2)
;CHECKSYM-NEXT: StorageMappingClass: XMC_RO (0x1)
;CHECKSYM-NEXT: StabInfoIndex: 0x0
;CHECKSYM-NEXT: StabSectNum: 0x0
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: Symbol {
;CHECKSYM-NEXT: Index: [[#Index+4]]
;CHECKSYM-NEXT: Name: .L__const.main.cnst16
;CHECKSYM-NEXT: Value (RelocatableAddress): 0x30
;CHECKSYM-NEXT: Section: .text
;CHECKSYM-NEXT: Type: 0x0
;CHECKSYM-NEXT: StorageClass: C_HIDEXT (0x6B)
;CHECKSYM-NEXT: NumberOfAuxEntries: 1
;CHECKSYM-NEXT: CSECT Auxiliary Entry {
;CHECKSYM-NEXT: Index: [[#Index+5]]
;CHECKSYM-NEXT: ContainingCsectSymbolIndex: [[#Index]]
;CHECKSYM-NEXT: ParameterHashIndex: 0x0
;CHECKSYM-NEXT: TypeChkSectNum: 0x0
;CHECKSYM-NEXT: SymbolAlignmentLog2: 0
;CHECKSYM-NEXT: SymbolType: XTY_LD (0x2)
;CHECKSYM-NEXT: StorageMappingClass: XMC_RO (0x1)
;CHECKSYM-NEXT: StabInfoIndex: 0x0
;CHECKSYM-NEXT: StabSectNum: 0x0
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: Symbol {
;CHECKSYM-NEXT: Index: [[#Index+6]]
;CHECKSYM-NEXT: Name: .L__const.main.cnst8
;CHECKSYM-NEXT: Value (RelocatableAddress): 0x40
;CHECKSYM-NEXT: Section: .text
;CHECKSYM-NEXT: Type: 0x0
;CHECKSYM-NEXT: StorageClass: C_HIDEXT (0x6B)
;CHECKSYM-NEXT: NumberOfAuxEntries: 1
;CHECKSYM-NEXT: CSECT Auxiliary Entry {
;CHECKSYM-NEXT: Index: [[#Index+7]]
;CHECKSYM-NEXT: ContainingCsectSymbolIndex: [[#Index]]
;CHECKSYM-NEXT: ParameterHashIndex: 0x0
;CHECKSYM-NEXT: TypeChkSectNum: 0x0
;CHECKSYM-NEXT: SymbolAlignmentLog2: 0
;CHECKSYM-NEXT: SymbolType: XTY_LD (0x2)
;CHECKSYM-NEXT: StorageMappingClass: XMC_RO (0x1)
;CHECKSYM-NEXT: StabInfoIndex: 0x0
;CHECKSYM-NEXT: StabSectNum: 0x0
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: Symbol {
;CHECKSYM-NEXT: Index: [[#Index+8]]
;CHECKSYM-NEXT: Name: .L__const.main.cnst4
;CHECKSYM-NEXT: Value (RelocatableAddress): 0x48
;CHECKSYM-NEXT: Section: .text
;CHECKSYM-NEXT: Type: 0x0
;CHECKSYM-NEXT: StorageClass: C_HIDEXT (0x6B)
;CHECKSYM-NEXT: NumberOfAuxEntries: 1
;CHECKSYM-NEXT: CSECT Auxiliary Entry {
;CHECKSYM-NEXT: Index: [[#Index+9]]
;CHECKSYM-NEXT: ContainingCsectSymbolIndex: [[#Index]]
;CHECKSYM-NEXT: ParameterHashIndex: 0x0
;CHECKSYM-NEXT: TypeChkSectNum: 0x0
;CHECKSYM-NEXT: SymbolAlignmentLog2: 0
;CHECKSYM-NEXT: SymbolType: XTY_LD (0x2)
;CHECKSYM-NEXT: StorageMappingClass: XMC_RO (0x1)
;CHECKSYM-NEXT: StabInfoIndex: 0x0
;CHECKSYM-NEXT: StabSectNum: 0x0
;CHECKSYM-NEXT: }
;CHECKSYM-NEXT: }

View File

@ -78,9 +78,6 @@ entry:
; CHECKOBJ-NEXT: 28: 68 65 6c 6c
; CHECKOBJ-NEXT: 2c: 6f 20 77 6f
; CHECKOBJ-NEXT: 30: 72 6c 64 21
; CHECKOBJ-NEXT: 34: 0a 00 61 62 {{.*}}{{[[:space:]] *}}
; CHECKOBJ-NEXT: 00000036 .L.str:
; CHECKOBJ-NEXT: 36: 61 62 63 64
; CHECKOBJ-NEXT: 3a: 65 66 67 68
; CHECKOBJ-NEXT: 3e: 00
; CHECKOBJ-NEXT: 3f: 00
; CHECKOBJ-NEXT: 34: 0a 00 61 62
; CHECKOBJ-NEXT: 38: 63 64 65 66
; CHECKOBJ-NEXT: 3c: 67 68 00 00