[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:05 PDT 2024
https://github.com/bd1976bris created https://github.com/llvm/llvm-project/pull/111139
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.
>From aa8daf044ecdbf60df412295ea5005ccf0c697bb Mon Sep 17 00:00:00 2001
From: bd1976bris <bd1976llvm at gmail.com>
Date: Fri, 4 Oct 2024 13:08:07 +0100
Subject: [PATCH] [LLD][ELF] Add assert for TargetInfo correctness for when ctx
becomes a local variable
TargetInfos are currently function-statics.
Add an assert to Guard against that causing problems if ctx is changed from a global variable to a local variable.
---
lld/ELF/Driver.cpp | 4 ++++
1 file changed, 4 insertions(+)
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
More information about the llvm-commits
mailing list