[llvm] 28fb69e - [AIX] Emit version string in .file directive
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 12 10:04:03 PDT 2021
Author: Jinsong Ji
Date: 2021-07-12T17:03:52Z
New Revision: 28fb69e00a4d3f3e59ccd63cf5c56c4af66a475c
URL: https://github.com/llvm/llvm-project/commit/28fb69e00a4d3f3e59ccd63cf5c56c4af66a475c
DIFF: https://github.com/llvm/llvm-project/commit/28fb69e00a4d3f3e59ccd63cf5c56c4af66a475c.diff
LOG: [AIX] Emit version string in .file directive
AIX .file directive support including compiler version string.
https://www.ibm.com/docs/en/aix/7.2?topic=ops-file-pseudo-op
This patch adds the support so that it will be easier to identify build
compiler in objects.
Reviewed By: #powerpc, shchenz
Differential Revision: https://reviews.llvm.org/D105743
Added:
Modified:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/MC/MCObjectStreamer.h
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/MC/MCAsmInfoXCOFF.cpp
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll
llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll
llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index b1d6b7fb7fd34..355f569861d8c 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -390,6 +390,10 @@ class MCAsmInfo {
/// for ELF targets. Defaults to true.
bool HasSingleParameterDotFile = true;
+ /// True if the target has a four strings .file directive, strings seperated
+ /// by comma. Defaults to false.
+ bool HasFourStringsDotFile = false;
+
/// True if the target has a .ident directive, this is true for ELF targets.
/// Defaults to false.
bool HasIdentDirective = false;
@@ -729,6 +733,7 @@ class MCAsmInfo {
bool hasFunctionAlignment() const { return HasFunctionAlignment; }
bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
+ bool hasFourStringsDotFile() const { return HasFourStringsDotFile; }
bool hasIdentDirective() const { return HasIdentDirective; }
bool hasNoDeadStrip() const { return HasNoDeadStrip; }
bool hasAltEntry() const { return HasAltEntry; }
diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
index a0169c4c82280..dcdee2b5774b1 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -184,6 +184,8 @@ class MCObjectStreamer : public MCStreamer {
void emitNops(int64_t NumBytes, int64_t ControlledNopLength,
SMLoc Loc) override;
void emitFileDirective(StringRef Filename) override;
+ void emitFileDirective(StringRef Filename, StringRef CompilerVerion,
+ StringRef TimeStamp, StringRef Description) override;
void emitAddrsig() override;
void emitAddrsigSym(const MCSymbol *Sym) override;
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index d6ed2111ce8b4..fd326ff187124 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -854,6 +854,10 @@ class MCStreamer {
/// "foo.c"' assembler directive.
virtual void emitFileDirective(StringRef Filename);
+ /// Emit ".file assembler diretive with additioal info.
+ virtual void emitFileDirective(StringRef Filename, StringRef CompilerVerion,
+ StringRef TimeStamp, StringRef Description);
+
/// Emit the "identifiers" directive. This implements the
/// '.ident "version foo"' assembler directive.
virtual void emitIdent(StringRef IdentString) {}
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index a1507a349d431..90797c6d571aa 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -59,6 +59,7 @@
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
+#include "llvm/Config/config.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constant.h"
@@ -297,11 +298,24 @@ bool AsmPrinter::doInitialization(Module &M) {
// don't, this at least helps the user find where a global came from.
if (MAI->hasSingleParameterDotFile()) {
// .file "foo.c"
+
+ SmallString<128> FileName;
if (MAI->hasBasenameOnlyForFileDirective())
- OutStreamer->emitFileDirective(
- llvm::sys::path::filename(M.getSourceFileName()));
+ FileName = llvm::sys::path::filename(M.getSourceFileName());
else
- OutStreamer->emitFileDirective(M.getSourceFileName());
+ FileName = M.getSourceFileName();
+ if (MAI->hasFourStringsDotFile()) {
+#ifdef PACKAGE_VENDOR
+ const char VerStr[] =
+ PACKAGE_VENDOR " " PACKAGE_NAME " version " PACKAGE_VERSION;
+#else
+ const char VerStr[] = PACKAGE_NAME " version " PACKAGE_VERSION;
+#endif
+ // TODO: Add timestamp and description.
+ OutStreamer->emitFileDirective(FileName, VerStr, "", "");
+ } else {
+ OutStreamer->emitFileDirective(FileName);
+ }
}
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
diff --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
index 0006754acb86b..ae7afeb30099c 100644
--- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -22,6 +22,7 @@ MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
IsLittleEndian = false;
HasVisibilityOnlyWithLinkage = true;
HasBasenameOnlyForFileDirective = false;
+ HasFourStringsDotFile = true;
// For XCOFF, string constant consists of any number of characters enclosed in
// "" (double quotation marks).
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index f6d877c519f87..72f4ee3f33beb 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -253,6 +253,8 @@ class MCAsmStreamer final : public MCStreamer {
SMLoc Loc) override;
void emitFileDirective(StringRef Filename) override;
+ void emitFileDirective(StringRef Filename, StringRef CompilerVerion,
+ StringRef TimeStamp, StringRef Description) override;
Expected<unsigned> tryEmitDwarfFileDirective(unsigned FileNo,
StringRef Directory,
StringRef Filename,
@@ -1450,6 +1452,28 @@ void MCAsmStreamer::emitFileDirective(StringRef Filename) {
EmitEOL();
}
+void MCAsmStreamer::emitFileDirective(StringRef Filename,
+ StringRef CompilerVerion,
+ StringRef TimeStamp,
+ StringRef Description) {
+ assert(MAI->hasFourStringsDotFile());
+ OS << "\t.file\t";
+ PrintQuotedString(Filename, OS);
+ OS << ",";
+ if (!CompilerVerion.empty()) {
+ PrintQuotedString(CompilerVerion, OS);
+ }
+ if (!TimeStamp.empty()) {
+ OS << ",";
+ PrintQuotedString(TimeStamp, OS);
+ }
+ if (!Description.empty()) {
+ OS << ",";
+ PrintQuotedString(Description, OS);
+ }
+ EmitEOL();
+}
+
void MCAsmStreamer::printDwarfFileDirective(
unsigned FileNo, StringRef Directory, StringRef Filename,
Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source,
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 4dae2f41fc454..2865a2ad80a99 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -848,6 +848,14 @@ void MCObjectStreamer::emitFileDirective(StringRef Filename) {
getAssembler().addFileName(Filename);
}
+void MCObjectStreamer::emitFileDirective(StringRef Filename,
+ StringRef CompilerVerion,
+ StringRef TimeStamp,
+ StringRef Description) {
+ getAssembler().addFileName(Filename);
+ // TODO: add additional info to integrated assembler.
+}
+
void MCObjectStreamer::emitAddrsig() {
getAssembler().getWriter().emitAddrsigSection();
}
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 2a1998fd9c4c9..fc7fb555f0b9f 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -1147,6 +1147,9 @@ void MCStreamer::EndCOFFSymbolDef() {
llvm_unreachable("this directive only supported on COFF targets");
}
void MCStreamer::emitFileDirective(StringRef Filename) {}
+void MCStreamer::emitFileDirective(StringRef Filename, StringRef CompilerVerion,
+ StringRef TimeStamp, StringRef Description) {
+}
void MCStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
llvm_unreachable("this directive only supported on COFF targets");
}
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll b/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
index d5b6886ebcefe..be9f70d27e5ce 100644
--- a/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
@@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "/absolute/path/to/file"
+; CHECK-SAME: ,{{.*version}}
source_filename = "/absolute/path/to/file"
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll b/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll
index 6df85c84d2678..f4cb6d3d79636 100644
--- a/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll
@@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "../relative/path/to/file"
+; CHECK-SAME: ,{{.*version}}
source_filename = "../relative/path/to/file"
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll
index 05ef566bcf093..9735110024f5f 100644
--- a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll
@@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "1""2.c"
+; CHECK-SAME: ,{{.*version}}
source_filename = "1\222.c"
diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll
index a600494e151b4..6f75a3c455d83 100644
--- a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll
@@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "1'2.c"
+; CHECK-SAME: ,{{.*version}}
source_filename = "1'2.c"
More information about the llvm-commits
mailing list