Bug 31490 - [4.6 Regression] Compile error section type conflict
Summary: [4.6 Regression] Compile error section type conflict
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.6.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks: 33168
  Show dependency treegraph
 
Reported: 2007-04-06 01:27 UTC by Khem Raj
Modified: 2011-02-03 19:18 UTC (History)
16 users (show)

See Also:
Host:
Target: powerpc64-*-linux-gnu, ia64-*-*
Build:
Known to work:
Known to fail: 4.0.2, 4.1.0, 4.2.0, 4.3.0
Last reconfirmed: 2007-10-12 12:39:51


Attachments
testcase (547 bytes, text/plain)
2007-04-06 01:28 UTC, Khem Raj
Details
proposed patch (381 bytes, patch)
2007-05-18 14:57 UTC, Segher Boessenkool
Details | Diff
gcc46-pr31490.patch (2.45 KB, patch)
2011-01-27 14:09 UTC, Jakub Jelinek
Details | Diff
gcc46-pr31490.patch (3.53 KB, patch)
2011-01-27 15:00 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Khem Raj 2007-04-06 01:27:58 UTC
The attached testcase does not compile for ppc64 using gcc confgured to generate ppc/ppc64 code.

Attached is a reduced testcase from kernel. This error was not happening with gcc 4.2 snapshot from January. I think it is related to static inline and extern inline.

compile the attached testcase 

gcc -m64 -c test.c

test.c:51: error: __ksymtab_cpu_add_sysdev_attr_group causes a section type conflict
Comment 1 Khem Raj 2007-04-06 01:28:30 UTC
Created attachment 13333 [details]
testcase

testcase to reproduce the problem.
Comment 2 Andrew Pinski 2007-04-06 01:57:08 UTC
Reduced testcase:
int cpu_ (void *attr) {}
const unsigned long _1 __attribute__((section("__"))) =  (unsigned long)&cpu_ ;
const unsigned long _group __attribute__((section("__"))) = 0;
Comment 3 Andrew Pinski 2007-04-06 01:59:34 UTC
> This error was not happening with gcc 4.2 snapshot from January. 
My reduced testcase shows it happens even in 4.0.2.  I don't have any thing older than that right off hand.
Comment 4 Dinar Temirbulatov 2007-04-06 03:18:56 UTC
looks like regression is caused by PR26090 fix
Comment 5 Dinar Temirbulatov 2007-05-02 16:14:27 UTC
I can reproduce this bug any architecture with -fpic option
Comment 6 Dinar Temirbulatov 2007-05-02 16:25:57 UTC
workaround for the bug:
--- gcc/varasm.c-orig   2007-05-02 19:15:04.000000000 +0400
+++ gcc/varasm.c        2007-05-02 19:16:17.000000000 +0400
@@ -5519,6 +5519,8 @@ decl_readonly_section (tree decl, int re
     case SECCAT_RODATA_MERGE_STR_INIT:
     case SECCAT_RODATA_MERGE_CONST:
     case SECCAT_SRODATA:
+    case SECCAT_DATA_REL_RO:
+    case SECCAT_DATA_REL_RO_LOCAL:
       return true;
       break;
     default:
Comment 7 Andrew Pinski 2007-05-02 16:41:08 UTC
> I can reproduce this bug any architecture with -fpic option

Oh and this is why it fails without -fpic on powerpc64-linux-gnu as really it is always PIC with the toc based ABI.

>workaround for the bug:
Actually that looks like the correct fix from reading output.h's comment about these section categories.
Comment 8 Segher Boessenkool 2007-05-15 13:07:28 UTC
Bisecting shows that the original bug (powerpc64 Linux build
errors out) is caused by r122781.  I didn't actually test on 4.2
but the same patch is applied there (as r122782).

If the reduced testcase in comment #2 fails on older compilers,
it is likely a different bug (or an invalid testcase); if a bug, please
file a separate PR for it.
Comment 9 Dinar Temirbulatov 2007-05-16 22:47:34 UTC
This patch fixes both testcases

--- gcc/varasm.c.orig   2007-05-16 21:32:11.000000000 +0400
+++ gcc/varasm.c        2007-05-16 21:36:14.000000000 +0400
@@ -5762,12 +5762,14 @@ categorize_decl_for_section (tree decl, 
             be read-only or not, but whether the dynamic link will have to
             do something.  If so, we wish to segregate the data in order to
             minimize cache misses inside the dynamic linker.  */
-         if (reloc & targetm.asm_out.reloc_rw_mask ())
+         if (reloc & targetm.asm_out.reloc_rw_mask ()
+             && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
            ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
          else
            ret = SECCAT_DATA;
        }
-      else if (reloc & targetm.asm_out.reloc_rw_mask ())
+      else if (reloc & targetm.asm_out.reloc_rw_mask ()
+              && !lookup_attribute ("section", DECL_ATTRIBUTES (decl)))
        ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
       else if (reloc || flag_merge_constants < 2)
        /* C and C++ don't allow different variables to share the same

, bootstraped and tested on i686-pc-linux-gnu with no new regressions, tested 4.2 version with gdb-sim on following architectures arm-elf, arm-none-eabi, mips-elf, mipsisa64-elf, powerpc-eabisim, sh-elf, powerpc-unknown-eabispe with no new regressions
Comment 10 Segher Boessenkool 2007-05-18 14:57:31 UTC
Created attachment 13578 [details]
proposed patch

still need to run the testsuite on it
Comment 11 Andreas Schwab 2007-06-20 11:32:04 UTC
Also broken on ia64.
Comment 12 Janis Johnson 2007-08-27 21:54:04 UTC
Trunk currently fails on powerpc64-linux building libstdc++-v3/src/system_error.cc.  Hacking libtool a bit allows seeing the message "std::system_category causes a section type conflict".  The file is compiled with -O2 and -fdata-sections; if either of those is removed then the bootstrap succeeds.

This PR looked related (and Andrew Pinski confirmed that it is) so I tried the patch from comment #10; it needs more parens to avoid warnings, but with that patch the bootstrap succeeds.
Comment 13 Dinar Temirbulatov 2007-08-28 16:25:37 UTC
reviewed patch posted here http://gcc.gnu.org/ml/gcc-patches/2007-05/msg01280.html
Comment 14 Janis Johnson 2007-08-28 18:15:34 UTC
The patch that I tried is the one attached for comment #10, not the one in comment #9.  With that patch a bootstrap of all languages but Ada succeeded.  The test results look reasonable, although I don't have results from the last few days with which to compare them.
Comment 15 Daniel Jacobowitz 2007-08-31 17:42:40 UTC
Has Segher's patch been sent to gcc-patches?  I've just encountered the ppc64 bootstrap failure too.
Comment 16 Etienne Le Sueur 2007-11-28 05:11:53 UTC
I just tried compiling 2.6.23.9 ia64 and the compile failed citing drivers/char/ipmi/ipmi_si_intf.c:1095: error: __param_hotmod causes a section type conflict

gcc (GCC) 4.2.3 20071123 (prerelease) (Debian 4.2.2-4)
Comment 17 Steve Ellcey 2010-04-16 22:29:56 UTC
Is there any reason none of the patches created for this bug have been checked in?  I still get a 'section type conflict' on IA64 with the test case from Comment #2.
Comment 18 Nicolas VEYSSIERE 2010-11-09 10:58:14 UTC
Hello, I have the same question as #17, I am using GCC on ia64 too, and this problem is still in the last version of GCC (4.4.5), and if I apply the patch of Dinar Temirbulatov (#9) it seems to works, (maybe I have to use the patch proposed by Segher Boessenkool, #10, i don't know).
Comment 19 Steve Ellcey 2010-11-17 22:54:07 UTC
Author: sje
Date: Wed Nov 17 22:54:05 2010
New Revision: 166887

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166887
Log:
2010-11-17  Dinar Temirbulatov <dtemirbulatov@gmail.com>
	    Steve Ellcey  <sje@cup.hp.com>

	PR middle-end/31490
	* varasm.c (categorize_decl_for_section): Ignore reloc_rw_mask
	if section attribute used.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/varasm.c
Comment 20 Steve Ellcey 2010-11-17 22:55:05 UTC
Author: sje
Date: Wed Nov 17 22:55:01 2010
New Revision: 166888

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166888
Log:
2010-11-17  Steve Ellcey  <sje@cup.hp.com>

	PR middle-end/31490
	* gcc.dg/pr31490.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr31490.c
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 21 Jakub Jelinek 2011-01-27 14:00:25 UTC
This patch is wrong and causes DT_TEXTREL nscd.
The relocation mask should never be ignored, otherwise
static const char *const foo __attribute__((__used__, __section__ ("bar"))) = "baz";
is incorrectly put into readonly section with -fpie or -fpic, eventhough it must be writable.
Comment 22 Jakub Jelinek 2011-01-27 14:09:17 UTC
Created attachment 23140 [details]
gcc46-pr31490.patch

Incomplete patch.  pr31490-2.c testcase works (and thus the original one too),
but what still doesn't work is pr31490-3.c, as we call get_variable_section only from assemble_variable at which point we immediately switch_to_section and thus it is too late for the second variable to change section flags.
Comment 23 Jakub Jelinek 2011-01-27 15:00:27 UTC
Created attachment 23142 [details]
gcc46-pr31490.patch

Updated patch.
Comment 24 Jakub Jelinek 2011-02-03 19:12:11 UTC
Author: jakub
Date: Thu Feb  3 19:12:07 2011
New Revision: 169804

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169804
Log:
	PR middle-end/31490
	* output.h (SECTION_RELRO): Define.
	(SECTION_MACH_DEP): Adjust.
	(get_variable_section): New prototype.
	* varpool.c (varpool_finalize_named_section_flags): New function.
	(varpool_assemble_pending_decls): Call it.
	* cgraph.h (varpool_finalize_named_section_flags): New prototype.
	* cgraphunit.c (cgraph_output_in_order): Call
	varpool_finalize_named_section_flags.
	* varasm.c (get_section): Allow section flags conflicts between
	relro and read-only sections if the section hasn't been declared yet.
	Set SECTION_OVERRIDE after diagnosing section type conflict.
	(get_variable_section): No longer static.
	(default_section_type_flags): Use SECTION_WRITE | SECTION_RELRO for
	readonly sections that need relocations.
	(decl_readonly_section_1): New function.
	(decl_readonly_section): Use it.

	Revert:
	2010-11-17  Dinar Temirbulatov <dtemirbulatov@gmail.com>
		    Steve Ellcey  <sje@cup.hp.com>

	PR middle-end/31490
	* varasm.c (categorize_decl_for_section): Ignore reloc_rw_mask
	if section attribute used.

	* gcc.dg/pr31490-2.c: New test.
	* gcc.dg/pr31490-3.c: New test.
	* gcc.dg/pr31490-4.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr31490-2.c
    trunk/gcc/testsuite/gcc.dg/pr31490-3.c
    trunk/gcc/testsuite/gcc.dg/pr31490-4.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cgraph.h
    trunk/gcc/cgraphunit.c
    trunk/gcc/output.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/varasm.c
    trunk/gcc/varpool.c
Comment 25 Jakub Jelinek 2011-02-03 19:18:19 UTC
Fixed.