Skip to content

Conversation

@DavidSpickett
Copy link
Collaborator

@DavidSpickett DavidSpickett commented Oct 21, 2025

This test seems to have taken the lit documentation at its word:
https://llvm.org/docs/CommandGuide/lit.html#substitutions

"%t temporary file name unique to the test"

%t is in fact the path of a file. As suggested by the line below that describing %basename_t.

This test (I assume) assumed it was just the filename itself and so left a layout of:
$ tree tools/lld/test/
tools/lld/test/
├── CMakeFiles
├── ELF
│   └── Output
│   ├── aarch64-build-attributes.s.tmp
│   │   ├── pauth-bti-gcs.s
│   │   └── pauth-bti-pac.s
│   ├── aarch64-build-attributes.s.tmp.merged.o
│   ├── aarch64-build-attributes.s.tmp1.o
│   ├── aarch64-build-attributes.s.tmp2.o
│   └── aarch64-build-attributes.s.tmp3.o
├── Unit
│   └── lit.site.cfg.py
├── cmake_install.cmake
└── lit.site.cfg.py

Note how the 2 .s files are in the temp dir but the .o files are not. This is fine, it works, but it's going to cost someone time to unpick when this test actually does fail.

To fix this, remove %t from all the temp file names so they are created in the temp dir, which is cleaned before each run.

New layout:
$ tree tools/lld/test/
tools/lld/test/
├── CMakeFiles
├── ELF
│   └── Output
│   └── aarch64-build-attributes.s.tmp
│   ├── 1.o
│   ├── 2.o
│   ├── 3.o
│   ├── merged.o
│   ├── pauth-bti-gcs.s
│   └── pauth-bti-pac.s
├── Unit
│   └── lit.site.cfg.py
├── cmake_install.cmake
└── lit.site.cfg.py

This test made the foolish decision to take the lit documentation
at its word:
https://llvm.org/docs/CommandGuide/lit.html#substitutions

"%t temporary file name unique to the test"

%t is in fact the **path** of a file. As suggested by the line
below that describing %basename_t.

This test assumed it was just the filename itself and so left a
layout of:
$ tree tools/lld/test/
tools/lld/test/
├── CMakeFiles
├── ELF
│   └── Output
│       ├── aarch64-build-attributes.s.tmp
│       │   ├── pauth-bti-gcs.s
│       │   └── pauth-bti-pac.s
│       ├── aarch64-build-attributes.s.tmp.merged.o
│       ├── aarch64-build-attributes.s.tmp1.o
│       ├── aarch64-build-attributes.s.tmp2.o
│       └── aarch64-build-attributes.s.tmp3.o
├── Unit
│   └── lit.site.cfg.py
├── cmake_install.cmake
└── lit.site.cfg.py

Note how the 2 .s files are in the temp dir but the .o files
are not.

To fix this, remove %t from all the temp file names so they
are created in the temp dir, which is cleaned before each run.

New layout:
$ tree tools/lld/test/
tools/lld/test/
├── CMakeFiles
├── ELF
│   └── Output
│       └── aarch64-build-attributes.s.tmp
│           ├── 1.o
│           ├── 2.o
│           ├── 3.o
│           ├── merged.o
│           ├── pauth-bti-gcs.s
│           └── pauth-bti-pac.s
├── Unit
│   └── lit.site.cfg.py
├── cmake_install.cmake
└── lit.site.cfg.py
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2025

@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld

Author: David Spickett (DavidSpickett)

Changes

This test made the foolish decision to take the lit documentation at its word:
https://llvm.org/docs/CommandGuide/lit.html#substitutions

"%t temporary file name unique to the test"

%t is in fact the path of a file. As suggested by the line below that describing %basename_t.

This test assumed it was just the filename itself and so left a layout of:
$ tree tools/lld/test/
tools/lld/test/
├── CMakeFiles
├── ELF
│   └── Output
│   ├── aarch64-build-attributes.s.tmp
│   │   ├── pauth-bti-gcs.s
│   │   └── pauth-bti-pac.s
│   ├── aarch64-build-attributes.s.tmp.merged.o
│   ├── aarch64-build-attributes.s.tmp1.o
│   ├── aarch64-build-attributes.s.tmp2.o
│   └── aarch64-build-attributes.s.tmp3.o
├── Unit
│   └── lit.site.cfg.py
├── cmake_install.cmake
└── lit.site.cfg.py

Note how the 2 .s files are in the temp dir but the .o files are not.

To fix this, remove %t from all the temp file names so they are created in the temp dir, which is cleaned before each run.

New layout:
$ tree tools/lld/test/
tools/lld/test/
├── CMakeFiles
├── ELF
│   └── Output
│   └── aarch64-build-attributes.s.tmp
│   ├── 1.o
│   ├── 2.o
│   ├── 3.o
│   ├── merged.o
│   ├── pauth-bti-gcs.s
│   └── pauth-bti-pac.s
├── Unit
│   └── lit.site.cfg.py
├── cmake_install.cmake
└── lit.site.cfg.py


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

1 Files Affected:

  • (modified) lld/test/ELF/aarch64-build-attributes.s (+5-5)
diff --git a/lld/test/ELF/aarch64-build-attributes.s b/lld/test/ELF/aarch64-build-attributes.s
index f2d542150897e..3d333bf6ccf2f 100644
--- a/lld/test/ELF/aarch64-build-attributes.s
+++ b/lld/test/ELF/aarch64-build-attributes.s
@@ -1,11 +1,11 @@
 // REQUIRES: aarch64
 // RUN: rm -rf %t && split-file %s %t && cd %t
 
-// RUN: llvm-mc -triple=aarch64 -filetype=obj %s -o %t1.o
-// RUN: llvm-mc -triple=aarch64 -filetype=obj pauth-bti-gcs.s -o %t2.o
-// RUN: llvm-mc -triple=aarch64 -filetype=obj pauth-bti-pac.s -o %t3.o
-// RUN: ld.lld -r %t1.o %t2.o %t3.o -o %t.merged.o
-// RUN: llvm-readelf -n %t.merged.o | FileCheck %s --check-prefix=NOTE
+// RUN: llvm-mc -triple=aarch64 -filetype=obj %s -o 1.o
+// RUN: llvm-mc -triple=aarch64 -filetype=obj pauth-bti-gcs.s -o 2.o
+// RUN: llvm-mc -triple=aarch64 -filetype=obj pauth-bti-pac.s -o 3.o
+// RUN: ld.lld -r 1.o 2.o 3.o -o merged.o
+// RUN: llvm-readelf -n merged.o | FileCheck %s --check-prefix=NOTE
 
 /// This test merges three object files with AArch64 build attributes.
 /// All contain identical PAuth ABI info (platform/version), which must be preserved.

@DavidSpickett
Copy link
Collaborator Author

Will fix the lit docs in another PR.

DavidSpickett added a commit to DavidSpickett/llvm-project that referenced this pull request Oct 21, 2025
%t is currently documented as:
temporary file name unique to the test

Which I take to mean if the path is a/b/c/tempfile, then
%t would be tempfile. It is not, it's the whole path.

(which is hinted at by %basename_t, but why would you read
that if you didn't need to use it)

As seen in llvm#164396 this can create confusion when people use
it as if it were just the file name.

Make it clear in the docs that this is the path of a file.
@mstorsjo
Copy link
Member

This test made the foolish decision to take the lit documentation at its word: https://llvm.org/docs/CommandGuide/lit.html#substitutions

"%t temporary file name unique to the test"

%t is in fact the path of a file. As suggested by the line below that describing %basename_t.

This test assumed it was just the filename itself and so left a layout of:

I'm not sure if I'd make the same conclusion that this was a mistaken conclusion in itself though - it is fairly common among LLD tests to produce files like %t.obj and %t.exe without creating a temporary directory - and %t1.o sounds like another, rather terse, form of the same pattern. The fact that the test uses split-file with a temp dir named %t (and also cds into that directory) makes the pattern of generated files a bit inconsistent, but I don't see it as being wrong or mistaken in itself.

That said, I don't mind this change itself, but I wouldn't consider the previous form erroneous either - I would expect to see many similar cases among other LLD tests.

@DavidSpickett
Copy link
Collaborator Author

The inconsistency is the problem yes. That's the bit that will waste my time if I have to debug this test again.

Doing either is fine but tests should pick one or document why they need both. Not that I'm gonna hunt down the others but that's the principle.

@DavidSpickett
Copy link
Collaborator Author

This test made the foolish decision

And this is missing the British humour context of "(and such fools include myself)", so I've changed that. If I had written this test I wouldn't have noticed this either.

DavidSpickett added a commit that referenced this pull request Oct 24, 2025
%t is currently documented as:
temporary file name unique to the test

https://llvm.org/docs/CommandGuide/lit.html#substitutions

Which I take to mean if the path is a/b/c/tempfile, then %t would be
tempfile. It is not, it's the whole path.

(which is hinted at by %basename_t, but why would you read that if you
didn't need to use it)

As seen in #164396 this can create confusion when people use it as if it
were just the file name.

Make it clear in the docs that this is a unique path, which can be used
to make files or folders.
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
%t is currently documented as:
temporary file name unique to the test

https://llvm.org/docs/CommandGuide/lit.html#substitutions

Which I take to mean if the path is a/b/c/tempfile, then %t would be
tempfile. It is not, it's the whole path.

(which is hinted at by %basename_t, but why would you read that if you
didn't need to use it)

As seen in llvm#164396 this can create confusion when people use it as if it
were just the file name.

Make it clear in the docs that this is a unique path, which can be used
to make files or folders.
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.

3 participants