* fix crasher bug in varasm.c:function_section()
@ 2004-10-28 21:13 Zack Weinberg
0 siblings, 0 replies; only message in thread
From: Zack Weinberg @ 2004-10-28 21:13 UTC (permalink / raw)
To: gcc-patches
function_section() blindly calls get_insns(); however, it may be
called at a point where not only is there no insn chain, there's no
active cfun, and the compiler will crash. I can only trigger this
problem under somewhat exotic conditions - compiling .i files from a
-save-temps build of a native AIX compiler with a cross compiler from
Linux to AIX. (The crash does not happen in a native AIX build
because the operating system masks the problem by allowing null
pointers to be dereferenced.) function_section is defined (by its own
commentary) to handle being called for no active function, so I fix it
here.
As the comment I've added to the code says, I am dubious about
function_section looking for unlikely-execute notes in the first
place, but I am not inclined to mess with that, considering that we
know there are substantial problems with text partitioning, and the
fixes have been postponed to 4.1. This is the minimal defensive
change.
zw
* varasm.c (function_section): If DECL is NULL_TREE, don't try
to do anything else. Do not call get_insns if cfun or
cfun->emit are NULL.
===================================================================
Index: varasm.c
--- varasm.c 27 Oct 2004 09:22:02 -0000 1.457
+++ varasm.c 28 Oct 2004 20:48:50 -0000
@@ -563,26 +563,34 @@ asm_output_aligned_bss (FILE *file, tree
/* Switch to the section for function DECL.
- If DECL is NULL_TREE, switch to the text section.
- ??? It's not clear that we will ever be passed NULL_TREE, but it's
- safer to handle it. */
+ If DECL is NULL_TREE, switch to the text section. We can be passed
+ NULL_TREE under some circumstances by dbxout.c at least. */
void
function_section (tree decl)
{
+ if (decl == NULL_TREE)
+ text_section ();
+ else
+ {
+ /* ??? Typical use of this function maybe shouldn't be looking
+ for unlikely blocks at all - in the event that an entire
+ function is going into the unlikely-execute section, that
+ should be reflected in its DECL_SECTION_NAME. */
+ rtx insns = cfun && cfun->emit ? get_insns () : 0;
+ bool unlikely = insns && scan_ahead_for_unlikely_executed_note (insns);
+
#ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
- bool unlikely = scan_ahead_for_unlikely_executed_note (get_insns());
-
- targetm.asm_out.select_section (decl, unlikely, DECL_ALIGN (decl));
+ targetm.asm_out.select_section (decl, unlikely, DECL_ALIGN (decl));
#else
- if (scan_ahead_for_unlikely_executed_note (get_insns()))
- unlikely_text_section ();
- else if (decl != NULL_TREE
- && DECL_SECTION_NAME (decl) != NULL_TREE)
- named_section (decl, (char *) 0, 0);
- else
- text_section ();
+ if (unlikely)
+ unlikely_text_section ();
+ else if (DECL_SECTION_NAME (decl))
+ named_section (decl, 0, 0);
+ else
+ text_section ();
#endif
+ }
}
/* Switch to read-only data section associated with function DECL. */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-10-28 20:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-28 21:13 fix crasher bug in varasm.c:function_section() Zack Weinberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).