Skip to content

[LLD][ELF] Assert TargetInfo correctness for when ctx becomes a local #111139

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

Conversation

bd1976bris
Copy link
Collaborator

TargetInfos are currently function-statics, e.g:

static X86_64 t(ctx);
.

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

… 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.
@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2024

@llvm/pr-subscribers-lld

Author: bd1976bris (bd1976bris)

Changes

TargetInfos are currently function-statics, e.g:

static X86_64 t(ctx);
.

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 --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

@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2024

@llvm/pr-subscribers-lld-elf

Author: bd1976bris (bd1976bris)

Changes

TargetInfos are currently function-statics, e.g:

static X86_64 t(ctx);
.

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 --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

@MaskRay
Copy link
Member

MaskRay commented Oct 6, 2024

With #111206 this should be unnecessary

@bd1976bris
Copy link
Collaborator Author

With #111206 this should be unnecessary

Thanks. I'll resolve this in favor of #111206.

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