Skip to content

Conversation

@kosarev
Copy link
Collaborator

@kosarev kosarev commented Oct 16, 2024

They may be not known.

@kosarev kosarev requested a review from MaskRay October 16, 2024 13:36
@llvmbot llvmbot added the llvm:mc Machine (object) code label Oct 16, 2024
@kosarev kosarev force-pushed the fix-switchtosection branch from 3bd56e3 to c9d2e73 Compare October 16, 2024 13:36
@llvmbot
Copy link
Member

llvmbot commented Oct 16, 2024

@llvm/pr-subscribers-mc

Author: Ivan Kosarev (kosarev)

Changes

They may be not known.

Change-Id: I66543240af2d10d77b4f7f23c06553356b3ec767


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

1 Files Affected:

  • (modified) llvm/lib/MC/MCSectionELF.cpp (+4-2)
diff --git a/llvm/lib/MC/MCSectionELF.cpp b/llvm/lib/MC/MCSectionELF.cpp
index 25e62b70b5e2a0..3dc9a67e63939a 100644
--- a/llvm/lib/MC/MCSectionELF.cpp
+++ b/llvm/lib/MC/MCSectionELF.cpp
@@ -191,8 +191,10 @@ void MCSectionELF::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
   }
 
   if (Flags & ELF::SHF_GROUP) {
-    OS << ",";
-    printName(OS, Group.getPointer()->getName());
+    if (const MCSymbolELF *Signature = Group.getPointer()) {
+      OS << ",";
+      printName(OS, Signature->getName());
+    }
     if (isComdat())
       OS << ",comdat";
   }

@kosarev
Copy link
Collaborator Author

kosarev commented Oct 16, 2024

@MaskRay If this needs a test, can you give some pointers as to what it might look like and where we would want it, please? Not quite my area.

@MaskRay
Copy link
Member

MaskRay commented Oct 16, 2024

When is it unknown? We need a test.
If this only triggers in downstream code, I don't think we can change the code.

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

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

.

@kosarev
Copy link
Collaborator Author

kosarev commented Oct 16, 2024

Caught downstream, yes. The comment for the Group field in MCSectionELF.h reads like the pointer can be null:

  /// The section group signature symbol (if not null) and a bool indicating
  /// whether this is a GRP_COMDAT group.
  const PointerIntPair<const MCSymbolELF *, 1, bool> Group;

There's also a guarding if for the pointer in MCSectionELF constructor:

  MCSectionELF(StringRef Name, unsigned type, unsigned flags,
...
        Group(group, IsComdat), LinkedToSym(LinkedToSym) {
    if (Group.getPointer())
      Group.getPointer()->setIsSignature();
  }

@kosarev kosarev requested a review from petrhosek October 16, 2024 16:30
They may be not known.

Change-Id: Ie69060a2f7d049a11afa7b5e7c7f132ccb0a592d
@kosarev kosarev force-pushed the fix-switchtosection branch from c9d2e73 to 7354caa Compare October 17, 2024 16:39
@kosarev
Copy link
Collaborator Author

kosarev commented Oct 17, 2024

Added test.

@kosarev kosarev requested a review from MaskRay October 17, 2024 16:40
@MaskRay
Copy link
Member

MaskRay commented Oct 17, 2024

In the test you added

  // Test that switching to a group section with no associated signature name
  // doesn't crash.
  C.Streamer->switchSection(
      C.Ctx->getELFSection("foo", ELF::SHT_PROGBITS, ELF::SHF_GROUP));

I am still not convinced we should take the change. Perhaps we should disallow SHF_GROUP without a signature in switchSection. This isn't valid in ELF.

@kosarev
Copy link
Collaborator Author

kosarev commented Oct 17, 2024

Perhaps we should disallow SHF_GROUP without a signature in switchSection. This isn't valid in ELF.

Should the ELF loading code do the check then?

@MaskRay
Copy link
Member

MaskRay commented Oct 20, 2024

Perhaps we should disallow SHF_GROUP without a signature in switchSection. This isn't valid in ELF.

Should the ELF loading code do the check then?

The section creation code can have an assert

@kosarev
Copy link
Collaborator Author

kosarev commented Oct 20, 2024

Perhaps we should disallow SHF_GROUP without a signature in switchSection. This isn't valid in ELF.

Should the ELF loading code do the check then?

The section creation code can have an assert

Having the assert without the loading code erroring out signature-less group sections means we'll just crash on loading such ELFs.

@MaskRay
Copy link
Member

MaskRay commented Oct 23, 2024

We should avoid this construct when a SHF_GROUP section without a signature symbol is constructed. Factory functions can have this precondition.

@kosarev kosarev closed this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:mc Machine (object) code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants