Skip to content

Commit e5000ee

Browse files
author
Chen Zheng
committed
[XCOFF] make .file directive have directory info
The .file directive is changed to only have basename in D36018 for ELF. But on AIX, we require the .file directive to also contain the directory info. This aligns with other AIX compiler like XLC and is required by some AIX tool like DBX. Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D99785
1 parent 1798f22 commit e5000ee

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ class MCAsmInfo {
341341
/// argument and how it is interpreted. Defaults to NoAlignment.
342342
LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
343343

344+
/// True if the target only has basename for .file directive. False if the
345+
/// target also needs the directory along with the basename. Default to true.
346+
bool HasBasenameOnlyForFileDirective = true;
347+
344348
// True if the target allows .align directives on functions. This is true for
345349
// most targets, so defaults to true.
346350
bool HasFunctionAlignment = true;
@@ -666,6 +670,9 @@ class MCAsmInfo {
666670
return LCOMMDirectiveAlignmentType;
667671
}
668672

673+
bool hasBasenameOnlyForFileDirective() const {
674+
return HasBasenameOnlyForFileDirective;
675+
}
669676
bool hasFunctionAlignment() const { return HasFunctionAlignment; }
670677
bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
671678
bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,11 @@ bool AsmPrinter::doInitialization(Module &M) {
297297
// don't, this at least helps the user find where a global came from.
298298
if (MAI->hasSingleParameterDotFile()) {
299299
// .file "foo.c"
300-
OutStreamer->emitFileDirective(
301-
llvm::sys::path::filename(M.getSourceFileName()));
300+
if (MAI->hasBasenameOnlyForFileDirective())
301+
OutStreamer->emitFileDirective(
302+
llvm::sys::path::filename(M.getSourceFileName()));
303+
else
304+
OutStreamer->emitFileDirective(M.getSourceFileName());
302305
}
303306

304307
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();

llvm/lib/MC/MCAsmInfoXCOFF.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void MCAsmInfoXCOFF::anchor() {}
1919
MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
2020
IsLittleEndian = false;
2121
HasVisibilityOnlyWithLinkage = true;
22+
HasBasenameOnlyForFileDirective = false;
2223
PrivateGlobalPrefix = "L..";
2324
PrivateLabelPrefix = "L..";
2425
SupportsQuotedNames = false;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \
2+
; RUN: | FileCheck %s
3+
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \
4+
; RUN: | FileCheck %s
5+
6+
; CHECK: .file "/absolute/path/to/file"
7+
8+
source_filename = "/absolute/path/to/file"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \
2+
; RUN: | FileCheck %s
3+
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \
4+
; RUN: | FileCheck %s
5+
6+
; CHECK: .file "../relative/path/to/file"
7+
8+
source_filename = "../relative/path/to/file"

0 commit comments

Comments
 (0)