Skip to content

[ELF] Improve comment of InputSection::file and update getFile. NFC #79550

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

MaskRay
Copy link
Member

@MaskRay MaskRay commented Jan 26, 2024

Clarify a comment after #78944.

All uses of getFile() assert file is non-null. getFile is not used with a
synthetic section. Replace cast_or_null with cast.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Jan 26, 2024

@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld

Author: Fangrui Song (MaskRay)

Changes

Clarify a comment after #78944.

All uses of getFile() assert file is non-null. It is not used with a
synthetic section. Replace cast_or_null with cast.


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

1 Files Affected:

  • (modified) lld/ELF/InputSection.h (+5-4)
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index dda4242d8be1c1f..bb9dff38ae02995 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -118,9 +118,9 @@ class InputSectionBase : public SectionBase {
 
   static bool classof(const SectionBase *s) { return s->kind() != Output; }
 
-  // The file which contains this section. Its dynamic type is always
-  // ObjFile<ELFT>, but in order to avoid ELFT, we use InputFile as
-  // its static type.
+  // The file which contains this section. Its dynamic type is usually
+  // ObjFile<ELFT>, but may be an InputFile of InternalKind (for a synthetic
+  // section).
   InputFile *file;
 
   // Input sections are part of an output section. Special sections
@@ -132,8 +132,9 @@ class InputSectionBase : public SectionBase {
   // Section index of the relocation section if exists.
   uint32_t relSecIdx = 0;
 
+  // Getter when the dynamic type is ObjFile<ELFT>.
   template <class ELFT> ObjFile<ELFT> *getFile() const {
-    return cast_or_null<ObjFile<ELFT>>(file);
+    return cast<ObjFile<ELFT>>(file);
   }
 
   // Used by --optimize-bb-jumps and RISC-V linker relaxation temporarily to

Copy link
Collaborator

@smithp35 smithp35 left a comment

Choose a reason for hiding this comment

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

LGTM, may be worth seeing if nga888 is happy with it too.

Copy link
Collaborator

@nga888 nga888 left a comment

Choose a reason for hiding this comment

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

LGTM too!

@MaskRay MaskRay merged commit 26cc651 into main Jan 26, 2024
@MaskRay MaskRay deleted the users/MaskRay/spr/elf-improve-comment-of-inputsectionfile-and-update-getfile-nfc branch January 26, 2024 18:43
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