Article View: gnu.gcc.help
Article #144Re: SPARC assember directive ".text" generated by GCC 1.40
From: John Clark
Date: Thu, 23 Jul 1992 00:54
Date: Thu, 23 Jul 1992 00:54
101 lines
3324 bytes
3324 bytes
In article <1992Jul22.194602.17372@amhux2.amherst.edu> twpierce@amhux1.amherst.edu (Tim Pierce) writes:
+
+GCC generates a ".text" assembler directive at the beginning of
>programs that utilize constant strings, apparently to inform the
+assembler that the following section of the program stores text.
+Example, from a program that includes the statement
+"printf ("%d\n", i)":
+
+gcc_compiled.:
+.text
+LC0:
+ .ascii "%d\12\0"
+ .align 4
+.global _main
+ .proc 1
+ ...
+
+I cannot find mention of the .text directive anywhere in the Sun-4
+assembler manual, nor in the SPARC Architecture Manual from SPARC
The '.text' and '.data' directives are the only way to choose which
of the 3 segments to place data in an 'a.out' file, for the standard
GNU gas assembler. The 3rd is the BSS(Block Storage Segment) directive
'.comm' which causes space to be allocated when the program is loaded
but cannot be used to initialize data.
'.text' refers to the code segment, '.data' to initialized data.
If you had the 'gas' document I think these directives are mentioned
there. Even more ancient, is the MIT 'as' doc.
The reason why strings wind up in '.text' is that 'guarentes' the
non-writeableness of them. Older compilers were haphazard about
where strings such as "mktmpXXXXXX" would wind up, and so one could
have
tmpfileName = mktemp( "mktmpXXXXXX" );
Which the subroutine would re-write 'XXXXXX' with a unique number,
typically the process id number, and the program could then use for
a unique file name.
This is a bozo no-no in modern times, and so one must do some thing
like the following,
char TempFileName[] = "mktmpXXXXX";/* initialize a data segement string */
func()
{
mktemp( TempFileName ); /* Create a unique string value */
}
Alternatively, you can use the '-fwriteable-strings' option and have
the good old days symantics about strings, i.e. you would have:
/Public/Gnu/LIBC/glibc-1.03 (174) gcc -S -O -fwritable-strings t.c
/Public/Gnu/LIBC/glibc-1.03 (175) more t.s
gcc2_compiled.:
.data
.align 8
LC0:
.ascii "test of writeable strings\12\0"
.text
.align 4
.global _main
.proc 04
_main:
!#PROLOGUE# 0
save %sp,-136,%sp
!#PROLOGUE# 1
call ___main,0
nop
sethi %hi(LC0),%o0
call _printf,0
or %o0,%lo(LC0),%o0
ret
restore
/Public/Gnu/LIBC/glibc-1.03 (176)
As for the Sun4 reference manuals on 'as', the '.text' is
implemented as:
.seg "text"
and ".data" as:
.seg "data"
and ".comm" as:
.seg "bss"
VarName:
.skip 32 ! allocate 32 bytes of storage for
! character buffer VarName.
--
John Clark
jclark@ucsd.edu
Technical Details
Message-ID:
<36006@sdcc12.ucsd.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!network.ucsd.edu!sdcc12!sdcc3!jclarkReferences:
<1992Jul22.194602.17372@amhux2.amherst.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!ames!network.ucsd.edu!sdcc12!sdcc3!jclark From: jclark@sdcc3.ucsd.edu (John Clark) Newsgroups: gnu.gcc.help,comp.sys.sun.hardware,comp.sys.sun.misc,comp.unix.solaris Subject: Re: SPARC assember directive ".text" generated by GCC 1.40 Message-ID: <36006@sdcc12.ucsd.edu> Date: 23 Jul 92 00:54:34 GMT References: <1992Jul22.194602.17372@amhux2.amherst.edu> Sender: news@sdcc12.ucsd.edu Followup-To: gnu.gcc.help Organization: University of California, San Diego Lines: 101 Nntp-Posting-Host: sdcc3.ucsd.edu