On Mon, Aug 28, 2017 at 11:42:53AM -0600, Jeff Law wrote: > On 07/17/2017 08:35 AM, Joerg Sonnenberger wrote: > > Hello, > > attached patch fixes inconsistent handling of section flags when using > > the section attribute, i.e.: > > > > __attribute__((section("writable1"))) int foo1; > > __attribute__((section("readonly1"))) const int foo1c; > > __attribute__((section("writable2"))) int foo2 = 42; > > __attribute__((section("readonly2"))) const int foo2c = 42; > > > > should give section attributes of "aw", "a", "aw", "a" in that order. > > Currently, "foo1c" is classified as BSS though and therefore put into a > > writable section. > ISTM the test we need here is whether or not the underlying DECL is > readonly. If it READONLY, then it shouldn't go into .bss, but should > instead to into a readable section. > > Testing based on names seems wrong. > > Does the attached (untested) patch work for you?
The intention should work, will test it. The attached patch will likely also be needed on top. Joerg
Index: varasm.c =================================================================== RCS file: /home/joerg/repo/netbsd/src/external/gpl3/gcc/dist/gcc/varasm.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -p -r1.2 -r1.3 --- varasm.c 17 Jul 2017 19:53:10 -0000 1.2 +++ varasm.c 22 Jul 2017 20:52:52 -0000 1.3 @@ -6428,7 +6428,8 @@ categorize_decl_for_section (const_tree location. -fmerge-all-constants allows even that (at the expense of not conforming). */ ret = SECCAT_RODATA; - else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST) + else if (DECL_INITIAL (decl) != NULL + && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST) ret = SECCAT_RODATA_MERGE_STR_INIT; else ret = SECCAT_RODATA_MERGE_CONST;