gcc and strings(1)

Tom Tkacik tkacik at kyzyl.mi.org
Thu Mar 7 21:43:02 AEST 1991


In article <11898 at alice.att.com>, wilber at alice.att.com (rew) writes:
> Does gcc put strings in a funny place?  When I compile a program using
> the stock cc and shared libraries, strings(1) finds the string literals
> just fine (with no -a option).  When I compile the same program using gcc
> and the shared libraries strings(1) doesn't find any strings.  (Unless I
> use -a, in which case a lot of junky pseudo-strings are found as well.)
> (I'm using the strings program from osu-cis.)

Being and ANSI C compiler gcc is allowed to make string constants constant.
It does so by placing them in the read-only .text segment along with
the program.  Cc places all string constants in the .data section
(where the initialized data goes).  Strings(1) looks only in the .data
section unless given the -a option, as you discovered.

If you want gcc to put all strings in the .data section, it's easy.
Simply use gcc -fwritable-strings.  That tells gcc to make all strings
writable, with the effect that they have to go where strings(1)
can find them.

-- 
Tom Tkacik                |
tkacik at kyzyl.mi.org       |     To rent this space, call 1-800-555-QUIP.
...!rphroy!kyzyl!tkacik   |



More information about the Comp.sys.3b1 mailing list