1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[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
This commit is contained in:
Jinsong Ji 2021-07-12 03:37:06 +00:00
parent 512e92b224
commit 41284718d3
12 changed files with 68 additions and 3 deletions

View File

@ -390,6 +390,10 @@ protected:
/// 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 @@ public:
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; }

View File

@ -184,6 +184,8 @@ public:
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;

View File

@ -854,6 +854,10 @@ public:
/// "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) {}

View File

@ -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>();

View File

@ -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).

View File

@ -253,6 +253,8 @@ public:
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,

View File

@ -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();
}

View File

@ -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");
}

View File

@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "/absolute/path/to/file"
; CHECK-SAME: ,{{.*version}}
source_filename = "/absolute/path/to/file"

View File

@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "../relative/path/to/file"
; CHECK-SAME: ,{{.*version}}
source_filename = "../relative/path/to/file"

View File

@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "1""2.c"
; CHECK-SAME: ,{{.*version}}
source_filename = "1\222.c"

View File

@ -4,5 +4,6 @@
; RUN: | FileCheck %s
; CHECK: .file "1'2.c"
; CHECK-SAME: ,{{.*version}}
source_filename = "1'2.c"