[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-11-12 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

Iain Sandoe iains at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||FIXED

--- Comment #29 from Iain Sandoe iains at gcc dot gnu.org 2011-11-12 14:05:32 
UTC ---
fixed.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-11-12 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #28 from Iain Sandoe iains at gcc dot gnu.org 2011-11-12 14:05:03 
UTC ---
Author: iains
Date: Sat Nov 12 14:04:58 2011
New Revision: 181314

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=181314
Log:

gcc/objc:

Backport from mainline
2011-10-29  Iain Sandoe  ia...@gcc.gnu.org

PR target/47997
* objc-act.c (objc_build_string_object): Remove redundant second
call to fix_string_type ().  Add a checking assert that we are,
indeed, passed a STRING_CST.


Modified:
branches/gcc-4_6-branch/gcc/objc/ChangeLog
branches/gcc-4_6-branch/gcc/objc/objc-act.c


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-10-29 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #26 from Iain Sandoe iains at gcc dot gnu.org 2011-10-29 12:59:33 
UTC ---
Author: iains
Date: Sat Oct 29 12:59:30 2011
New Revision: 180653

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=180653
Log:

gcc/objc:

PR target/47997
* objc-act.c (objc_build_string_object): Remove redundant second
call to fix_string_type ().  Add a checking assert that we are,
indeed, passed a STRING_CST.


Modified:
trunk/gcc/objc/ChangeLog
trunk/gcc/objc/objc-act.c


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-10-29 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #27 from Iain Sandoe iains at gcc dot gnu.org 2011-10-29 13:03:27 
UTC ---
let's give it a few weeks on trunk - and then back-port to 4.6 if all is OK
(since we just missed the 4.6.2 release).


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-09-08 Thread tobias.netzel at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #25 from Tobias Netzel tobias.netzel at googlemail dot com 
2011-09-08 16:27:21 UTC ---
As for me the patch does what it is expected to do; no more linker warnings
when linking objective-c code. I didn't notice anything that might be broken by
it.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-08-31 Thread mrs at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #24 from mrs at gcc dot gnu.org mrs at gcc dot gnu.org 2011-08-31 
17:55:19 UTC ---
I don't have a take on the best way to fix this.  With that said, if you like
the last patch and it tests out, Ok.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-21 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #20 from Iain Sandoe iains at gcc dot gnu.org 2011-07-21 07:54:51 
UTC ---
hm .. I think this might be a new (objc). bug, rather than a back-end problem;
since it doesn't show with normal c-strings (even when compiled -x
objective-c).  

Will try to take a look.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-21 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #21 from Iain Sandoe iains at gcc dot gnu.org 2011-07-21 09:05:10 
UTC ---
This is indeed a new bug - if there is to be any lengthly deliberation, please
move it to its own PR (against objective-c).



calling fix_string_type () on a tree that is already a STRING_CST appears to
break things.. 

(the size and unit_size fields get screwed up).

... this might be intended [i.e. we should not call the function when we
already have a STRING_CST]
(or indicate a bug elsewhere).

I am assuming the former for now ergo, try this:

Index: gcc/objc/objc-act.c
===
--- gcc/objc/objc-act.c (revision 176554)
+++ gcc/objc/objc-act.c (working copy)
@@ -3132,10 +3132,13 @@ objc_build_string_object (tree string)
   struct string_descriptor *desc, key;
   void **loc;

-  /* Prep the string argument.  */
-  string = fix_string_type (string);
-  TREE_SET_CODE (string, STRING_CST);
-  length = TREE_STRING_LENGTH (string) - 1;
+  if (TREE_CODE (string) != STRING_CST)
+{
+  /* Prep the string argument.  */
+  string = fix_string_type (string);
+  TREE_SET_CODE (string, STRING_CST);
+  length = TREE_STRING_LENGTH (string) - 1;
+}

   /* The target may have different ideas on how to construct an ObjC string
  literal.  On Darwin (Mac OS X), for example, we may wish to obtain a


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-21 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #22 from Iain Sandoe iains at gcc dot gnu.org 2011-07-21 10:36:02 
UTC ---
hmm, comment #21 is not the right solution ...  (even if it works)

... the right solution is either  
   (a) to handle arrays of arbitrary-sized ints in fix_string_type () (without
assuming that they are whar when not explicitly set to
char{,16,32}_array_type_node)

   or

   (b) to force the type of CPP_OBJC_STRING to be char{,16,32}_array_type_node
as appropriate.

a. might look something like:

Index: gcc/c-family/c-common.c
===
--- gcc/c-family/c-common.c (revision 176554)
+++ gcc/c-family/c-common.c (working copy)
@@ -911,6 +911,32 @@ fix_string_type (tree value)
   nchars = length / (TYPE_PRECISION (char32_type_node) / BITS_PER_UNIT);
   e_type = char32_type_node;
 }
+  else if (TREE_TYPE (value)  TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
+{
+  int prec;
+
+  if (TREE_TYPE (TREE_TYPE ((value
+prec = TYPE_PRECISION (TREE_TYPE (TREE_TYPE ((value;
+  else
+prec = TYPE_PRECISION (wchar_type_node);
+
+  nchars = length / (prec / BITS_PER_UNIT);
+  switch (prec)
+{
+   case BITS_PER_UNIT:
+ e_type = char_type_node;
+ break;
+   case 16:
+ e_type = char16_type_node;
+ break;
+   case 32:
+ e_type = char32_type_node;
+ break;
+   default:
+ e_type = wchar_type_node;
+ break;
+   }
+}
   else
 {
   nchars = length / (TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT);

b. needs some more investigation.

thoughts?


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-21 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #23 from Iain Sandoe iains at gcc dot gnu.org 2011-07-21 14:52:26 
UTC ---
OK, done some more debugging 

so one can't call fix_string_type () twice on the same string and get a
sensible result...
... the determination of the string type by equating to one of the global_tree
nodes is broken on the second call since the first call overwrites the tree
type:

code fragment from fix_string_type ():

  i_type = build_index_type (size_int (nchars - 1));
  a_type = build_array_type (e_type, i_type);
  if (c_dialect_cxx() || warn_write_strings)
a_type = c_build_qualified_type (a_type, TYPE_QUAL_CONST);

  TREE_TYPE (value) = a_type;

===

So either this is wrong - or we need some way to know that fix_string_type has
already been called (by lex_string()).

in the meantime - this just avoids making the second call, because I can't see
that there's any case in which objc_build_string_object () is called without a
string from lex_string ()?  
(grep suggests not).

thus; assuming that fix_string_type () is behaving as expected, the following
is a fix :

Index: gcc/objc/objc-act.c
===
--- gcc/objc/objc-act.c (revision 176554)
+++ gcc/objc/objc-act.c (working copy)
@@ -3132,9 +3132,8 @@ objc_build_string_object (tree string)
   struct string_descriptor *desc, key;
   void **loc;

-  /* Prep the string argument.  */
-  string = fix_string_type (string);
-  TREE_SET_CODE (string, STRING_CST);
+  gcc_checking_assert (TREE_CODE (string) == STRING_CST);
+
   length = TREE_STRING_LENGTH (string) - 1;

   /* The target may have different ideas on how to construct an ObjC string


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-20 Thread tobias.netzel at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #15 from Tobias Netzel tobias.netzel at googlemail dot com 
2011-07-20 20:51:12 UTC ---
Created attachment 24800
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=24800
sample objective-c code that still causes the warning

Said warning does still occur when linking many Objective-C and Objective-C++
files from the mozilla codebase.
The attached sample code and playing a little with it reveals the following
behaviour of gcc:
(to be compiled as follows: gcc main.m -framework Foundation)
- the strings Me, Myself, I, Three, a, b, c, d, e, f and 
are put into (__TEXT,__const) - warning
- the strings One, Two, You and foo are put into (__TEXT,__cstring) -
no warning
- when adding more strings to NSMutableArray *mutable or to the
initialization of NSArray *arr, all strings that have a length other than
three characters are put into (__TEXT,__const) (- warning) and all strings of
exactly three characters are put into (__TEXT,__cstring) (- no warning)
- when there's only one string in (__TEXT,__const) there is no warning!


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-20 Thread tobias.netzel at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

Tobias Netzel tobias.netzel at googlemail dot com changed:

   What|Removed |Added

 CC||tobias.netzel at googlemail
   ||dot com

--- Comment #16 from Tobias Netzel tobias.netzel at googlemail dot com 
2011-07-20 20:53:38 UTC ---
Forgot to mention that there weren't any warnings with the 1st (unaccepted)
patch applied.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-20 Thread mrs at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

m...@gcc.gnu.org mrs at gcc dot gnu.org changed:

   What|Removed |Added

 Status|RESOLVED|NEW
 Resolution|FIXED   |

--- Comment #17 from mrs at gcc dot gnu.org mrs at gcc dot gnu.org 2011-07-20 
21:15:07 UTC ---
If your not happy, we're not happy.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-20 Thread mrs at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #18 from mrs at gcc dot gnu.org mrs at gcc dot gnu.org 2011-07-20 
21:25:37 UTC ---
Iain, I'm thinking we should do your code unconditionally for darwin10 and
later.  In darwin10.h, we put:

#define LINKER_PEDANTICALLY_WANTS_CSTRING 1

and then in the code:

   if ((LINKER_PEDANTICALLY_WANTS_CSTRING
   || darwin_constant_cfstrings || flag_merge_constants)
TREE_CODE (exp) == STRING_CST
TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
align = 256

Another possibility, is to just _always_ do this:

   if (TREE_CODE (exp) == STRING_CST
TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
align = 256

thoughts?  Jack, if you do the testsuite run, I'll check it in if it works. 
I'm a little nervous about the release branch...  :-(  Linker, shut up, would
have been my preference, but, I don't know if we have that option.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-07-20 Thread tobias.netzel at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #19 from Tobias Netzel tobias.netzel at googlemail dot com 
2011-07-20 21:53:16 UTC ---
(In reply to comment #18)
 Iain, I'm thinking we should do your code unconditionally for darwin10 and
 later.  In darwin10.h, we put:

To me it seems that specifying LINKER_PEDANTICALLY_WANTS_CSTRING would only do
the same thing as passing -mconstant-cfstrings to gcc. And passing
-mconstant-cfstrings doesn't change anything in my case.
The only thing that helps in my case is the first patch.
You should also be aware that one can build and use (I do) the linker from
darwin10 in earlier versions of the OS.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-06-28 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #13 from Iain Sandoe iains at gcc dot gnu.org 2011-06-28 09:16:08 
UTC ---
Author: iains
Date: Tue Jun 28 09:16:04 2011
New Revision: 175578

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=175578
Log:

PR target/47997
* config/darwin.c (darwin_mergeable_string_section): Place string
constants in '.cstring' rather than '.const' when CF/NSStrings are
active.


Modified:
branches/gcc-4_6-branch/gcc/ChangeLog
branches/gcc-4_6-branch/gcc/config/darwin.c


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-06-28 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

Iain Sandoe iains at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||FIXED

--- Comment #14 from Iain Sandoe iains at gcc dot gnu.org 2011-06-28 09:17:47 
UTC ---
fixed on trunk and 4.6 branch (sorry it took a while to commit the fix).


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-06-26 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #12 from Iain Sandoe iains at gcc dot gnu.org 2011-06-26 16:25:32 
UTC ---
Author: iains
Date: Sun Jun 26 16:25:29 2011
New Revision: 175410

URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=175410
Log:

PR target/47997
* config/darwin.c (darwin_mergeable_string_section): Place string
constants in '.cstring' rather than '.const' when CF/NSStrings are
active.


Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/darwin.c


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-12 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #9 from Iain Sandoe iains at gcc dot gnu.org 2011-03-12 10:08:56 
UTC ---
(In reply to comment #8)

firstly, I don't think you need to worry overly about the warning (we do place
the strings in the __TEXT segment, just not in the __cfstring section).  IMO ld
is being somewhat picky ... 
(but perhaps there is good reason for some future plans we're not aware of)

 What are the plans? Are you going to submit the fix to 4.6?

I doubt I'll have a chance before 4.6 forks -- we must be pretty close to that
... but ...

I'm currently testing a less intrusive patch (if people would like to check
this with different variants of XCode - and Mike approves it - perhaps it could
be done in time):

Index: gcc/config/darwin.c
===
--- gcc/config/darwin.c (revision 170897)
+++ gcc/config/darwin.c (working copy)
@@ -1195,7 +1195,11 @@ static section *
 darwin_mergeable_string_section (tree exp,
 unsigned HOST_WIDE_INT align)
 {
-  if (flag_merge_constants
+  /* Darwin's ld expects to see non-writable string literals in the .cstring 
+ section.  Later versions of ld check and complain when CFStrings are 
+ enabled.  Therefore we shall force the strings into .cstring since we
+ don't support writable ones anyway.  */
+  if ((darwin_constant_cfstrings || flag_merge_constants)
TREE_CODE (exp) == STRING_CST
TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
align = 256


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-12 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #10 from Iain Sandoe iains at gcc dot gnu.org 2011-03-12 13:45:38 
UTC ---
patch @ comment #9 works for me on *-darwin9 (places the strings in .cstring).

I would propose this rather than the one in comment #2.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-12 Thread mikestump at comcast dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #11 from Mike Stump mikestump at comcast dot net 2011-03-12 
16:23:45 UTC ---
Ok for the patch in comment #9.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-11 Thread anatol.pomozov at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #8 from Anatol anatol.pomozov at gmail dot com 2011-03-12 
04:50:22 UTC ---
What are the plans? Are you going to submit the fix to 4.6?

How can I help you with testing?


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-07 Thread howarth at nitro dot med.uc.edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #4 from Jack Howarth howarth at nitro dot med.uc.edu 2011-03-07 
15:37:54 UTC ---
The proposed patch in Comment 2 fixes the problem testcase and causes no
regressions on x86_64-apple-darwin10.

http://gcc.gnu.org/ml/gcc-testresults/2011-03/msg00571.html


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-07 Thread mrs at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

m...@gcc.gnu.org mrs at gcc dot gnu.org changed:

   What|Removed |Added

 CC||mrs at gcc dot gnu.org

--- Comment #5 from mrs at gcc dot gnu.org mrs at gcc dot gnu.org 2011-03-07 
17:45:29 UTC ---
Ok.  I'm hoping you double checked the incantation with the other version that
exists.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-07 Thread howarth at nitro dot med.uc.edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #6 from Jack Howarth howarth at nitro dot med.uc.edu 2011-03-07 
17:46:58 UTC ---
(In reply to comment #5)
 Ok.  I'm hoping you double checked the incantation with the other version that
 exists.

How would I do that?


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-07 Thread mikestump at comcast dot net
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

--- Comment #7 from Mike Stump mikestump at comcast dot net 2011-03-07 
18:16:13 UTC ---
Ok, you can look for strlen (s) == IDENTIFIER_LENGTH (x) in either the
darwin.[ch] files, or, failing one there, in the backend files...  I know I've
seen one before, just can't recall where exactly.  In theory, the two should be
virtually identical, or one of them is wrong.


[Bug target/47997] gcc on macosx: ld: warning: -fwritable-strings not compatible with literal CF/NSString

2011-03-05 Thread iains at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47997

Iain Sandoe iains at gcc dot gnu.org changed:

   What|Removed |Added

 Target||x86_64-apple-darwin10
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2011.03.05 10:18:04
  Component|c   |target
 Ever Confirmed|0   |1

--- Comment #3 from Iain Sandoe iains at gcc dot gnu.org 2011-03-05 10:18:04 
UTC ---
... changing category to 'target'
... not reproducible on Darwin9 (OSX 10.5).