nw.sc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # Copyright (C) 2014-2015 Free Software Foundation, Inc.
  2. #
  3. # Copying and distribution of this file, with or without modification,
  4. # are permitted in any medium without royalty provided the copyright
  5. # notice and this notice are preserved.
  6. #
  7. # Unusual variables checked by this code:
  8. # NOP - four byte opcode for no-op (defaults to 0)
  9. # DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
  10. # OTHER_READONLY_SECTIONS - other than .text .init .ctors .rodata ...
  11. # (e.g., .PARISC.milli)
  12. # OTHER_READWRITE_SECTIONS - other than .data .bss .sdata ...
  13. # (e.g., .PARISC.global)
  14. # OTHER_SECTIONS - at the end
  15. # EXECUTABLE_SYMBOLS - symbols that must be defined for an
  16. # executable (e.g., _DYNAMIC_LINK)
  17. # TEXT_START_SYMBOLS - symbols that appear at the start of the
  18. # .text section.
  19. # DATA_START_SYMBOLS - symbols that appear at the start of the
  20. # .data section.
  21. # OTHER_BSS_SYMBOLS - symbols that appear at the start of the
  22. # .bss section besides __bss_start.
  23. # DATA_PLT - .plt should be in data segment, not text segment.
  24. #
  25. # When adding sections, do note that the names of some sections are used
  26. # when specifying the start address of the next.
  27. #
  28. test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  29. test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
  30. test "$LD_FLAG" = "N" && DATA_ADDR=.
  31. INTERP=".interp ${RELOCATING-0} : { *(.interp) }"
  32. PLT=".plt ${RELOCATING-0} : { *(.plt) }"
  33. cat <<EOF
  34. /* Copyright (C) 2014-2015 Free Software Foundation, Inc.
  35. Copying and distribution of this script, with or without modification,
  36. are permitted in any medium without royalty provided the copyright
  37. notice and this notice are preserved. */
  38. OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
  39. "${LITTLE_OUTPUT_FORMAT}")
  40. OUTPUT_ARCH(${ARCH})
  41. ${RELOCATING+${LIB_SEARCH_DIRS}}
  42. ${RELOCATING+/* Do we need any of these for elf?
  43. __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */}
  44. ${RELOCATING+${EXECUTABLE_SYMBOLS}}
  45. ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
  46. if gld -r is used and the intermediate file has sections starting
  47. at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld
  48. bug. But for now assigning the zero vmas works. */}
  49. SECTIONS
  50. {
  51. /* Read-only sections, merged into text segment: */
  52. ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_START_ADDR} + SIZEOF_HEADERS;}}
  53. ${CREATE_SHLIB+${RELOCATING+. = SIZEOF_HEADERS;}}
  54. ${CREATE_SHLIB-${INTERP}}
  55. .hash ${RELOCATING-0} : { *(.hash) }
  56. .dynsym ${RELOCATING-0} : { *(.dynsym) }
  57. .dynstr ${RELOCATING-0} : { *(.dynstr) }
  58. .rel.text ${RELOCATING-0} : { *(.rel.text) }
  59. .rela.text ${RELOCATING-0} : { *(.rela.text) }
  60. .rel.data ${RELOCATING-0} : { *(.rel.data) }
  61. .rela.data ${RELOCATING-0} : { *(.rela.data) }
  62. .rel.rodata ${RELOCATING-0} : { *(.rel.rodata) }
  63. .rela.rodata ${RELOCATING-0} : { *(.rela.rodata) }
  64. .rel.got ${RELOCATING-0} : { *(.rel.got) }
  65. .rela.got ${RELOCATING-0} : { *(.rela.got) }
  66. .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) }
  67. .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) }
  68. .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) }
  69. .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) }
  70. .rel.bss ${RELOCATING-0} : { *(.rel.bss) }
  71. .rela.bss ${RELOCATING-0} : { *(.rela.bss) }
  72. .rel.plt ${RELOCATING-0} : { *(.rel.plt) }
  73. .rela.plt ${RELOCATING-0} : { *(.rela.plt) }
  74. .init ${RELOCATING-0} : { *(.init) } =${NOP-0}
  75. ${DATA_PLT-${PLT}}
  76. .text ${RELOCATING-0} :
  77. {
  78. ${RELOCATING+${TEXT_START_SYMBOLS}}
  79. *(.text)
  80. ${CONSTRUCTING+ __CTOR_LIST__ = .;}
  81. ${CONSTRUCTING+ LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)}
  82. ${CONSTRUCTING+ *(.ctors)}
  83. ${CONSTRUCTING+ LONG(0)}
  84. ${CONSTRUCTING+ __CTOR_END__ = .;}
  85. ${CONSTRUCTING+ __DTOR_LIST__ = .;}
  86. ${CONSTRUCTING+ LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)}
  87. ${CONSTRUCTING+ *(.dtors)}
  88. ${CONSTRUCTING+ LONG(0)}
  89. ${CONSTRUCTING+ __DTOR_END__ = .;}
  90. }
  91. ${RELOCATING+_etext = .;}
  92. ${RELOCATING+PROVIDE (etext = .);}
  93. .fini ${RELOCATING-0} : { *(.fini) } =${NOP-0}
  94. .ctors ${RELOCATING-0} : { *(.ctors) }
  95. .dtors ${RELOCATING-0} : { *(.dtors) }
  96. .rodata ${RELOCATING-0} : { *(.rodata) }
  97. .rodata1 ${RELOCATING-0} : { *(.rodata1) }
  98. ${OTHER_READONLY_SECTIONS}
  99. /* Read-write section, merged into data segment: */
  100. ${RELOCATING+. = ${DATA_ADDR- ALIGN(8) + ${MAXPAGESIZE}};}
  101. .data ${RELOCATING-0} :
  102. {
  103. ${RELOCATING+${DATA_START_SYMBOLS}}
  104. *(.data)
  105. ${CONSTRUCTING+CONSTRUCTORS}
  106. }
  107. .data1 ${RELOCATING-0} : { *(.data1) }
  108. ${OTHER_READWRITE_SECTIONS}
  109. .got ${RELOCATING-0} : { *(.got.plt) *(.got) }
  110. .dynamic ${RELOCATING-0} : { *(.dynamic) }
  111. ${DATA_PLT+${PLT}}
  112. /* We want the small data sections together, so single-instruction offsets
  113. can access them all, and initialized data all before uninitialized, so
  114. we can shorten the on-disk segment size. */
  115. .sdata ${RELOCATING-0} : { *(.sdata) }
  116. ${RELOCATING+_edata = .;}
  117. ${RELOCATING+PROVIDE (edata = .);}
  118. ${RELOCATING+__bss_start = .;}
  119. ${RELOCATING+${OTHER_BSS_SYMBOLS}}
  120. .sbss ${RELOCATING-0} : { *(.sbss) *(.scommon) }
  121. .bss ${RELOCATING-0} :
  122. {
  123. *(.dynbss)
  124. *(.bss)
  125. *(COMMON)
  126. }
  127. ${RELOCATING+_end = . ;}
  128. ${RELOCATING+PROVIDE (end = .);}
  129. /* These are needed for ELF backends which have not yet been
  130. converted to the new style linker. */
  131. .stab 0 : { *(.stab) }
  132. .stabstr 0 : { *(.stabstr) }
  133. ${OTHER_SECTIONS}
  134. }
  135. EOF