[llvm] c7c7ef8 - [XCOFF] set fragment for XMC_PR csects.

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 04:18:10 PST 2022


Author: esmeyi
Date: 2022-11-22T07:17:44-05:00
New Revision: c7c7ef8bda1fb7a81f8f769c6b1cc8583629a309

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

LOG: [XCOFF] set fragment for XMC_PR csects.

Summary: -xcoff-traceback-table is a default option on AIX regardless of optimization and debug levels. An error of relocation for paired relocatable term is not yet supported in XCOFFObjectWriter::recordRelocation occurred when both of the -xcoff-traceback-table and -function-sections are enabled.
The root cause is that we missed to calculate the symbols difference as absolute value before adding fixups when symbol_A without the fragment set is the csect itself and symbol_B is in it.
This patch only sets the fragment for XMC_PR csects because we don't have other cases that hit this problem yet.

Reviewed By: DiggerLin, hubert.reinterpretcast

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

Added: 
    

Modified: 
    llvm/lib/MC/MCContext.cpp
    llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 81f13ccb2da9..205e272d3ace 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -828,6 +828,14 @@ MCSectionXCOFF *MCContext::getXCOFFSection(
   if (Begin)
     Begin->setFragment(F);
 
+  // We might miss calculating the symbols 
diff erence as absolute value before
+  // adding fixups when symbol_A without the fragment set is the csect itself
+  // and symbol_B is in it.
+  // TODO: Currently we only set the fragment for XMC_PR csects because we don't
+  // have other cases that hit this problem yet.
+  if (!IsDwarfSec && CsectProp->MappingClass == XCOFF::XMC_PR)
+    QualName->setFragment(F);
+
   return Result;
 }
 

diff  --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
index 029865eb4ffa..767e38a8d5d1 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
@@ -5,6 +5,18 @@
 ; RUN:     -mattr=-altivec -function-sections < %s | \
 ; RUN:   FileCheck --check-prefix=ASM %s
 
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN:     -mattr=-altivec -function-sections -xcoff-traceback-table=true \
+; RUN:     -filetype=obj -o %t32.o < %s
+; RUN: llvm-objdump --syms --reloc --symbol-description %t32.o | \
+; RUN:   FileCheck --check-prefix=XCOFF32 %s
+
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr4 \
+; RUN:     -mattr=-altivec -function-sections -xcoff-traceback-table=true \
+; RUN:     -filetype=obj -o %t64.o < %s
+; RUN: llvm-objdump --syms --reloc --symbol-description %t64.o | \
+; RUN:   FileCheck --check-prefix=XCOFF64 %s
+
 @alias_foo = alias void (...), bitcast (void ()* @foo to void (...)*)
 
 define void @foo() {
@@ -93,3 +105,74 @@ entry:
 ; ASM-NEXT:  	.extern	extern_foo[DS]
 ; ASM-NEXT:  	.globl	alias_foo
 ; ASM-NEXT:  	.globl	.alias_foo
+
+; XCOFF32:      SYMBOL TABLE:
+; XCOFF32-NEXT: 00000000      df *DEBUG*	00000000 (idx: 0) <stdin>
+; XCOFF32-NEXT: 00000000         *UND*	00000000 (idx: 1) .extern_foo[PR]
+; XCOFF32-NEXT: 00000000         *UND*	00000000 (idx: 3) extern_foo[DS]
+; XCOFF32-NEXT: 00000000 l       .text	00000000 (idx: 5) .text[PR]
+; XCOFF32-NEXT: 00000000 g       .text	00000019 (idx: 7) .foo[PR]
+; XCOFF32-NEXT: 00000000 g     F .text (csect: (idx: 7) .foo[PR]) 	00000000 (idx: 9) .alias_foo
+; XCOFF32-NEXT: 00000020 g       .text	00000020 .hidden (idx: 11) .hidden_foo[PR]
+; XCOFF32-NEXT: 00000040 g       .text	00000059 (idx: 13) .bar[PR]
+; XCOFF32-NEXT: 000000c0 l       .text	0000002a (idx: 15) .static_overalign_foo[PR]
+; XCOFF32-NEXT: 000000ec g     O .data	0000000c (idx: 17) foo[DS]
+; XCOFF32-NEXT: 000000ec g     O .data (csect: (idx: 17) foo[DS]) 	00000000 (idx: 19) alias_foo
+; XCOFF32-NEXT: 000000f8 g     O .data	0000000c .hidden (idx: 21) hidden_foo[DS]
+; XCOFF32-NEXT: 00000104 g     O .data	0000000c (idx: 23) bar[DS]
+; XCOFF32-NEXT: 00000110 l     O .data	0000000c (idx: 25) static_overalign_foo[DS]
+; XCOFF32-NEXT: 0000011c l       .data	00000000 (idx: 27) TOC[TC0]
+
+; XCOFF32:      RELOCATION RECORDS FOR [.text]:
+; XCOFF32-NEXT: OFFSET   TYPE                     VALUE
+; XCOFF32-NEXT: 0000004c R_RBR                    (idx: 7) .foo[PR]
+; XCOFF32-NEXT: 00000054 R_RBR                    (idx: 15) .static_overalign_foo[PR]
+; XCOFF32-NEXT: 0000005c R_RBR                    (idx: 9) .alias_foo
+; XCOFF32-NEXT: 00000064 R_RBR                    (idx: 1) .extern_foo[PR]
+; XCOFF32-NEXT: 0000006c R_RBR                    (idx: 11) .hidden_foo[PR]
+; XCOFF32:      RELOCATION RECORDS FOR [.data]:
+; XCOFF32-NEXT: OFFSET   TYPE                     VALUE
+; XCOFF32-NEXT: 00000000 R_POS                    (idx: 7) .foo[PR]
+; XCOFF32-NEXT: 00000004 R_POS                    (idx: 27) TOC[TC0]
+; XCOFF32-NEXT: 0000000c R_POS                    (idx: 11) .hidden_foo[PR]
+; XCOFF32-NEXT: 00000010 R_POS                    (idx: 27) TOC[TC0]
+; XCOFF32-NEXT: 00000018 R_POS                    (idx: 13) .bar[PR]
+; XCOFF32-NEXT: 0000001c R_POS                    (idx: 27) TOC[TC0]
+; XCOFF32-NEXT: 00000024 R_POS                    (idx: 15) .static_overalign_foo[PR]
+; XCOFF32-NEXT: 00000028 R_POS                    (idx: 27) TOC[TC0]
+
+
+; XCOFF64:      SYMBOL TABLE:
+; XCOFF64-NEXT: 0000000000000000      df *DEBUG*	0000000000000000 (idx: 0) <stdin>
+; XCOFF64-NEXT: 0000000000000000         *UND*	0000000000000000 (idx: 1) .extern_foo[PR]
+; XCOFF64-NEXT: 0000000000000000         *UND*	0000000000000000 (idx: 3) extern_foo[DS]
+; XCOFF64-NEXT: 0000000000000000 l       .text	0000000000000000 (idx: 5) .text[PR]
+; XCOFF64-NEXT: 0000000000000000 g       .text	0000000000000019 (idx: 7) .foo[PR]
+; XCOFF64-NEXT: 0000000000000000 g     F .text (csect: (idx: 7) .foo[PR]) 	0000000000000000 (idx: 9) .alias_foo
+; XCOFF64-NEXT: 0000000000000020 g       .text	0000000000000020 .hidden (idx: 11) .hidden_foo[PR]
+; XCOFF64-NEXT: 0000000000000040 g       .text	0000000000000059 (idx: 13) .bar[PR]
+; XCOFF64-NEXT: 00000000000000c0 l       .text	000000000000002a (idx: 15) .static_overalign_foo[PR]
+; XCOFF64-NEXT: 00000000000000f0 g     O .data	0000000000000018 (idx: 17) foo[DS]
+; XCOFF64-NEXT: 00000000000000f0 g     O .data (csect: (idx: 17) foo[DS]) 	0000000000000000 (idx: 19) alias_foo
+; XCOFF64-NEXT: 0000000000000108 g     O .data	0000000000000018 .hidden (idx: 21) hidden_foo[DS]
+; XCOFF64-NEXT: 0000000000000120 g     O .data	0000000000000018 (idx: 23) bar[DS]
+; XCOFF64-NEXT: 0000000000000138 l     O .data	0000000000000018 (idx: 25) static_overalign_foo[DS]
+; XCOFF64-NEXT: 0000000000000150 l       .data	0000000000000000 (idx: 27) TOC[TC0]
+
+; XCOFF64:      RELOCATION RECORDS FOR [.text]:
+; XCOFF64-NEXT: OFFSET           TYPE                     VALUE
+; XCOFF64-NEXT: 000000000000004c R_RBR                    (idx: 7) .foo[PR]
+; XCOFF64-NEXT: 0000000000000054 R_RBR                    (idx: 15) .static_overalign_foo[PR]
+; XCOFF64-NEXT: 000000000000005c R_RBR                    (idx: 9) .alias_foo
+; XCOFF64-NEXT: 0000000000000064 R_RBR                    (idx: 1) .extern_foo[PR]
+; XCOFF64-NEXT: 000000000000006c R_RBR                    (idx: 11) .hidden_foo[PR]
+; XCOFF64:      RELOCATION RECORDS FOR [.data]:
+; XCOFF64-NEXT: OFFSET           TYPE                     VALUE
+; XCOFF64-NEXT: 0000000000000000 R_POS                    (idx: 7) .foo[PR]
+; XCOFF64-NEXT: 0000000000000008 R_POS                    (idx: 27) TOC[TC0]
+; XCOFF64-NEXT: 0000000000000018 R_POS                    (idx: 11) .hidden_foo[PR]
+; XCOFF64-NEXT: 0000000000000020 R_POS                    (idx: 27) TOC[TC0]
+; XCOFF64-NEXT: 0000000000000030 R_POS                    (idx: 13) .bar[PR]
+; XCOFF64-NEXT: 0000000000000038 R_POS                    (idx: 27) TOC[TC0]
+; XCOFF64-NEXT: 0000000000000048 R_POS                    (idx: 15) .static_overalign_foo[PR]
+; XCOFF64-NEXT: 0000000000000050 R_POS                    (idx: 27) TOC[TC0]


        


More information about the llvm-commits mailing list