[lld] [LLD][ELF] Assert TargetInfo correctness for when ctx becomes a local (PR #111139)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 05:11:45 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-elf

Author: bd1976bris (bd1976bris)

<details>
<summary>Changes</summary>

TargetInfos are currently function-statics, e.g: https://github.com/llvm/llvm-project/blob/6294679faa8ae57873b7fcdc00a4deb522d31c38/lld/ELF/Arch/X86_64.cpp#L1257.

Add an assert to Guard against that causing problems if ctx is changed from a global variable to a local variable.

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


1 Files Affected:

- (modified) lld/ELF/Driver.cpp (+4) 


``````````diff
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 373505a9e965b7..5042c23fd7b07e 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -3123,6 +3123,10 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
   // relocations or writing a PLT section. It also contains target-dependent
   // values such as a default image base address.
   ctx.target = getTarget(ctx);
+  // Currently, the TargetInfo structures in are function-statics. Guard against
+  // that causing problems if ctx is changed from a global variable to a local
+  // variable.
+  assert(&ctx.target->ctx == &ctx);
 
   ctx.arg.eflags = ctx.target->calcEFlags();
   // maxPageSize (sometimes called abi page size) is the maximum page size that

``````````

</details>


https://github.com/llvm/llvm-project/pull/111139


More information about the llvm-commits mailing list