[PATCH] Segfault in AArch64 backend with -g and -mbig-endian

Renato Golin renato.golin at linaro.org
Thu Sep 4 03:53:30 PDT 2014

Comment at: lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp:538
@@ -537,3 +537,3 @@
     const MCSection *Sec = Fixup.getValue()->FindAssociatedSection();
-    const MCSectionELF *SecELF = static_cast<const MCSectionELF *>(Sec);
-    if (SecELF->getSectionName() == ".eh_frame")
+    const MCSectionELF *SecELF = dyn_cast_or_null<const MCSectionELF>(Sec);
+    if (SecELF && SecELF->getSectionName() == ".eh_frame")
olista01 wrote:
> rengolin wrote:
> > olista01 wrote:
> > > echristo wrote:
> > > > Fixup to a null section? How's that happen?
> > > This is the section associated with the value to put into the fixup location, not the section containing the fixup location. This can be null if:
> > >  * It is a symbol which is not defined by this translation unit
> > >  * It is the difference between two temporary symbols, for example to find the length of a debug data structure.
> > Is this a null section or not an ELF section? Your check seems to imply the latter, while I believe it's the former.
> > 
> > In that case, this would be better fixed in the caller, since the result of a null section means you're applying a fixup to a null section and propagating the error.
> MCExpr::FindAssociatedSection can return nullptr when the expression is a reference to a symbol not defined in this translation unit, so we do have to be able to handle nullptr here without it being an error.
Right, so, to reiterate Eric's idea:

A fixup having a location that:
1. was not defined in this unit doesn't make much sense
2. is the result of removed temporary value, should have been removed when the values got out of context

If the problem here is 1, than we need to know why we're trying to reach non-existent sections in the first place. If the problem is 2, we need to know how to delete the fixups related to just deleted values, so we don't come here with null pointers.

But, that's not necessarily part of this patch, since FindAssociatedSection() does return nullptr on those cases.

I'll defer to Eric to approve this.


More information about the llvm-commits mailing list