Skip to content

[AIX] Add git revision to .file string #88164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 1, 2024
Merged

[AIX] Add git revision to .file string #88164

merged 5 commits into from
May 1, 2024

Conversation

jakeegan
Copy link
Member

@jakeegan jakeegan commented Apr 9, 2024

If LLVM_APPEND_VC_REV is on, add the git revision to the .file string. The revision can be set with LLVM_FORCE_VC_REVISION.

Before:
.file "git_revision.cpp",,"LLVM version 19.0.0git"

After:
.file "git_revision.cpp",,"LLVM version 19.0.0git (LLVM_REVISION)"

@llvmbot
Copy link
Member

llvmbot commented Apr 9, 2024

@llvm/pr-subscribers-backend-powerpc

Author: Jake Egan (jakeegan)

Changes

If LLVM_APPEND_VC_REV is on, add the git revision to the .file string. The revision can be set with LLVM_FORCE_VC_REVISION.

Before:
.file "git_revision.cpp",,"LLVM version 19.0.0git"

After:
.file "git_revision.cpp",,"LLVM version 19.0.0git (LLVM_REVISION)"


Full diff: https://github.com/llvm/llvm-project/pull/88164.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+8-4)
  • (added) llvm/test/CodeGen/PowerPC/git_revision.ll (+13)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 721d144d7f4c67..1072fce89e3099 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -114,6 +114,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Timer.h"
+#include "llvm/Support/VCSRevision.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetMachine.h"
@@ -497,12 +498,15 @@ bool AsmPrinter::doInitialization(Module &M) {
     else
       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;
+#ifdef PACKAGE_VENDOR
+      PACKAGE_VENDOR " "
+#endif
+      PACKAGE_NAME " version " PACKAGE_VERSION
+#ifdef LLVM_REVISION
+      " (" LLVM_REVISION ")"
 #endif
+      ;
       // TODO: Add timestamp and description.
       OutStreamer->emitFileDirective(FileName, VerStr, "", "");
     } else {
diff --git a/llvm/test/CodeGen/PowerPC/git_revision.ll b/llvm/test/CodeGen/PowerPC/git_revision.ll
new file mode 100644
index 00000000000000..280c311c8bd7c8
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/git_revision.ll
@@ -0,0 +1,13 @@
+; Check that the git revision is contained in the assembly/object files
+
+; RUN: cd %S && git rev-parse HEAD > %t
+
+; RUN: llc < %s > %t.a.o
+; RUN: sed -n -e "/$(cat %t)/p" %t.a.o
+
+; RUN: llc -filetype=obj < %s > %t.b.o
+; RUN: sed -n -e "/$(cat %t)/p" %t.b.o
+
+source_filename = "git_revision.cpp"
+target datalayout = "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512"
+target triple = "powerpc64-ibm-aix7.2.0.0"

Copy link

github-actions bot commented Apr 9, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@jakeegan
Copy link
Member Author

Addressed comments

Copy link
Member

@daltenty daltenty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I left some additional nit's you should consider addressing before landing this

@jakeegan
Copy link
Member Author

Addressed nits

@jakeegan jakeegan merged commit 8cde1cf into llvm:main May 1, 2024
@jakeegan jakeegan deleted the hash branch May 1, 2024 00:37
milkice233 pushed a commit to fedora-riscv/llvm that referenced this pull request Jan 22, 2025
This already happens implicitly because we don't build from a git
checkout. However, currently this also breaks the build due to
llvm/llvm-project#88164. Avoid this by
explicitly disabling the option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants