home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / help / 1762 < prev    next >
Encoding:
Text File  |  1992-07-22  |  3.2 KB  |  116 lines

  1. Xref: sparky gnu.gcc.help:1762 comp.sys.sun.hardware:3497 comp.sys.sun.misc:3282 comp.unix.solaris:108
  2. Path: sparky!uunet!stanford.edu!ames!network.ucsd.edu!sdcc12!sdcc3!jclark
  3. From: jclark@sdcc3.ucsd.edu (John Clark)
  4. Newsgroups: gnu.gcc.help,comp.sys.sun.hardware,comp.sys.sun.misc,comp.unix.solaris
  5. Subject: Re: SPARC assember directive ".text" generated by GCC 1.40
  6. Message-ID: <36006@sdcc12.ucsd.edu>
  7. Date: 23 Jul 92 00:54:34 GMT
  8. References: <1992Jul22.194602.17372@amhux2.amherst.edu>
  9. Sender: news@sdcc12.ucsd.edu
  10. Followup-To: gnu.gcc.help
  11. Organization: University of California, San Diego
  12. Lines: 101
  13. Nntp-Posting-Host: sdcc3.ucsd.edu
  14.  
  15. In article <1992Jul22.194602.17372@amhux2.amherst.edu> twpierce@amhux1.amherst.edu (Tim Pierce) writes:
  16. +
  17. +GCC generates a ".text" assembler directive at the beginning of
  18. >programs that utilize constant strings, apparently to inform the
  19. +assembler that the following section of the program stores text.
  20. +Example, from a program that includes the statement
  21. +"printf ("%d\n", i)":
  22. +
  23. +gcc_compiled.:
  24. +.text
  25. +LC0:
  26. +    .ascii "%d\12\0"
  27. +    .align 4
  28. +.global _main
  29. +    .proc 1
  30. +    ...
  31. +
  32. +I cannot find mention of the .text directive anywhere in the Sun-4
  33. +assembler manual, nor in the SPARC Architecture Manual from SPARC
  34.  
  35. The '.text' and '.data' directives are the only way to choose which
  36. of the 3 segments to place data in an 'a.out' file, for the standard
  37. GNU gas assembler. The 3rd is the BSS(Block Storage Segment) directive
  38. '.comm' which causes space to be allocated when the program is loaded
  39. but cannot be used to initialize data.
  40.  
  41. '.text' refers to the code segment, '.data' to initialized data. 
  42.  
  43. If you had the 'gas' document I think these directives are mentioned
  44. there. Even more ancient, is the MIT 'as' doc.
  45.  
  46. The reason why strings wind up in '.text' is that 'guarentes' the
  47. non-writeableness of them. Older compilers were haphazard about
  48. where strings such as "mktmpXXXXXX" would wind up, and so one could
  49. have
  50.  
  51.     tmpfileName = mktemp( "mktmpXXXXXX" );
  52.  
  53. Which the subroutine would re-write 'XXXXXX' with a unique number,
  54. typically the process id number, and the program could then use for
  55. a unique file name.
  56.  
  57. This is a bozo no-no in modern times, and so one must do some thing
  58. like the following,
  59.  
  60. char TempFileName[] = "mktmpXXXXX";/* initialize a data segement string */
  61.  
  62. func()
  63. {
  64.     mktemp( TempFileName ); /* Create a unique string value */
  65. }
  66.  
  67. Alternatively, you can use the '-fwriteable-strings' option and have
  68. the good old days symantics about strings, i.e. you would have:
  69.  
  70.  
  71. /Public/Gnu/LIBC/glibc-1.03 (174) gcc -S -O -fwritable-strings t.c
  72. /Public/Gnu/LIBC/glibc-1.03 (175) more t.s
  73. gcc2_compiled.:
  74. .data
  75.         .align 8
  76. LC0:
  77.         .ascii "test of writeable strings\12\0"
  78. .text
  79.         .align 4
  80.         .global _main
  81.         .proc   04
  82. _main:
  83.         !#PROLOGUE# 0
  84.         save %sp,-136,%sp
  85.         !#PROLOGUE# 1
  86.         call ___main,0
  87.         nop
  88.         sethi %hi(LC0),%o0
  89.         call _printf,0
  90.         or %o0,%lo(LC0),%o0
  91.         ret
  92.         restore
  93.  
  94. /Public/Gnu/LIBC/glibc-1.03 (176)
  95.  
  96.  
  97. As for the Sun4 reference manuals on 'as', the '.text' is
  98. implemented as:
  99.  
  100.     .seg    "text"
  101.  
  102. and ".data" as:
  103.  
  104.     .seg    "data"
  105.  
  106. and ".comm" as:
  107.  
  108.     .seg    "bss"
  109. VarName:
  110.     .skip     32    ! allocate 32 bytes of storage for
  111.             ! character buffer VarName.
  112. -- 
  113.  
  114. John Clark
  115. jclark@ucsd.edu
  116.