diff mbox

PowerPC section type conflict

Message ID 4EEB2886.6040108@codesourcery.com
State New
Headers show

Commit Message

Chung-Lin Tang Dec. 16, 2011, 11:16 a.m. UTC
Hi, under powerpc targets, using -mrelocatable under some cases triggers
an error during final assembly generation: rs6000_assemble_integer()
calls varasm.c:unlikely_text_section_p(), and the call chain eventually
gets to where the section htab is queried for ".text.unlikely", and
fails because of mismatched section flags: "error: foo causes a section
type conflict"

This seems to happen after rev.167085, 4.6 branch is also affected.

The flag mismatch seems quite straightforward: current_function_decl is
passed in as the decl here, and as it's final assembly now, it is
NULL_TREE. varasm.c:default_section_type_flags() adds SECTION_WRITE to
its return value, and things get borked.

This patch simply adds a condition to the SECTION_CODE case, to include
when decl == NULL_TREE, and the queried section has a .text* name. I
think this should be the intuitive way, and it does allow the testcase
to compile.

Tested on a powerpc target, is this okay for trunk? (and maybe 4.6 too?)

Thanks,
Chung-Lin

2011-12-16  Chung-Lin Tang  <cltang@codesourcery.com>

	gcc/
	* varasm.c (default_section_type_flags): Set SECTION_CODE in
	flags when decl is NULL_TREE, and section name matches ".text*".

Comments

Richard Henderson Dec. 16, 2011, 10:21 p.m. UTC | #1
On 12/16/2011 03:16 AM, Chung-Lin Tang wrote:
> Hi, under powerpc targets, using -mrelocatable under some cases triggers
> an error during final assembly generation: rs6000_assemble_integer()
> calls varasm.c:unlikely_text_section_p(), and the call chain eventually
> gets to where the section htab is queried for ".text.unlikely", and
> fails because of mismatched section flags: "error: foo causes a section
> type conflict"
> 
> This seems to happen after rev.167085, 4.6 branch is also affected.
> 
> The flag mismatch seems quite straightforward: current_function_decl is
> passed in as the decl here, and as it's final assembly now, it is
> NULL_TREE. varasm.c:default_section_type_flags() adds SECTION_WRITE to
> its return value, and things get borked.

I don't understand what was put into .text.unlikely that was not a
function in the first place?  Did we try to put data there somewhere?


r~
Chung-Lin Tang Dec. 18, 2011, 6:36 a.m. UTC | #2
On 2011/12/17 06:21 AM, Richard Henderson wrote:
> On 12/16/2011 03:16 AM, Chung-Lin Tang wrote:
>> Hi, under powerpc targets, using -mrelocatable under some cases triggers
>> an error during final assembly generation: rs6000_assemble_integer()
>> calls varasm.c:unlikely_text_section_p(), and the call chain eventually
>> gets to where the section htab is queried for ".text.unlikely", and
>> fails because of mismatched section flags: "error: foo causes a section
>> type conflict"
>>
>> This seems to happen after rev.167085, 4.6 branch is also affected.
>>
>> The flag mismatch seems quite straightforward: current_function_decl is
>> passed in as the decl here, and as it's final assembly now, it is
>> NULL_TREE. varasm.c:default_section_type_flags() adds SECTION_WRITE to
>> its return value, and things get borked.
> 
> I don't understand what was put into .text.unlikely that was not a
> function in the first place?  Did we try to put data there somewhere?

I don't think it's that kind of problem; the powerpc backend uses
unlikely_text_section_p(), which compares the passed in argument section
and the value of function_section_1(current_function_decl,true).

Since current_function_decl is NULL at assembly phase, it retrieves
".text.unlikely" to test for equality. It's the retrieving/lookup that
fails here, because the default looked-up section flags set when decl ==
NULL does not really seem to make sense (adds SECTION_WRITE).

Chung-Lin
Richard Henderson Dec. 18, 2011, 7:18 p.m. UTC | #3
On 12/17/2011 10:36 PM, Chung-Lin Tang wrote:
> I don't think it's that kind of problem; the powerpc backend uses
> unlikely_text_section_p(), which compares the passed in argument section
> and the value of function_section_1(current_function_decl,true).

I think this might be the real bug, or something related.

> Since current_function_decl is NULL at assembly phase, it retrieves
> ".text.unlikely" to test for equality. It's the retrieving/lookup that
> fails here, because the default looked-up section flags set when decl ==
> NULL does not really seem to make sense (adds SECTION_WRITE).

current_function_decl is only null when we're not inside a function.

One possible fix is to test for current_function_section inside
unlikely_text_section_p.  However, I think that begs the question
of what in the world is actually going on in rs6000_assemble_integer.
Why are we testing for emitting data in text sections?
Chung-Lin Tang Dec. 19, 2011, 3:45 p.m. UTC | #4
On 2011/12/19 上午 03:18, Richard Henderson wrote:
> On 12/17/2011 10:36 PM, Chung-Lin Tang wrote:
>> I don't think it's that kind of problem; the powerpc backend uses
>> unlikely_text_section_p(), which compares the passed in argument section
>> and the value of function_section_1(current_function_decl,true).
> 
> I think this might be the real bug, or something related.
> 
>> Since current_function_decl is NULL at assembly phase, it retrieves
>> ".text.unlikely" to test for equality. It's the retrieving/lookup that
>> fails here, because the default looked-up section flags set when decl ==
>> NULL does not really seem to make sense (adds SECTION_WRITE).
> 
> current_function_decl is only null when we're not inside a function.
> 
> One possible fix is to test for current_function_section inside
> unlikely_text_section_p.  However, I think that begs the question
> of what in the world is actually going on in rs6000_assemble_integer.
> Why are we testing for emitting data in text sections?

I think I sort of mis-represented the context here; this was not really
during the assembly phase of a function, but already in
toplev.c:output_object_blocks().

I've created a bugzilla PR for this, with a testcase from U-boot, and a
minimal testcase: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51623

Thanks,
Chung-Lin
diff mbox

Patch

Index: trunk/gcc/varasm.c
===================================================================
--- trunk/gcc/varasm.c	(revision 182398)
+++ trunk/gcc/varasm.c	(working copy)
@@ -6218,7 +6218,8 @@ 
 {
   unsigned int flags;
 
-  if (decl && TREE_CODE (decl) == FUNCTION_DECL)
+  if (decl ? TREE_CODE (decl) == FUNCTION_DECL
+      : strncmp (name, ".text", 5) == 0)
     flags = SECTION_CODE;
   else if (decl)
     {