compress.exp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. # Expect script for ELF compressed debug section tests.
  2. # Copyright (C) 2010-2022 Free Software Foundation, Inc.
  3. #
  4. # This file is part of the GNU Binutils.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  19. # MA 02110-1301, USA.
  20. #
  21. # Exclude non-ELF targets.
  22. if ![is_elf_format] {
  23. return
  24. }
  25. # Skip targets where -shared is not supported
  26. if ![check_shared_lib_support] {
  27. return
  28. }
  29. # Check if compiler works
  30. if { ![check_compiler_available] } {
  31. return
  32. }
  33. if { ![ld_assemble $as "--compress-debug-sections $srcdir/$subdir/empty.s" tmpdir/empty.o ] } {
  34. fail "linker compressed debug sections"
  35. }
  36. if { ![ld_assemble $as "--compress-debug-sections=zlib-gabi $srcdir/$subdir/empty.s" tmpdir/emptyzlib.o ] } {
  37. fail "linker compressed debug sections"
  38. }
  39. set build_tests {
  40. {"Build libfoo.so with compressed debug sections"
  41. "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections"
  42. {foo.c} {} "libfoo.so"}
  43. {"Build libbar.so with compressed debug sections"
  44. "-shared -Wl,--compress-debug-sections=none"
  45. "-fPIC -ggdb3 -Wa,--compress-debug-sections"
  46. {begin.c end.c} {} "libbar.so"}
  47. {"Build libfoozlib.so with compressed debug sections with zlib-gabi"
  48. "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
  49. {foo.c} {} "libfoozlib.so"}
  50. {"Build libbarzlib.so with compressed debug sections with zlib-gabi"
  51. "-shared" "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
  52. {begin.c end.c} {} "libbarzlib.so"}
  53. {"Build libzlibfoo.so with zlib compressed debug sections"
  54. "-shared -Wl,--compress-debug-sections=zlib"
  55. "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib"
  56. {foo.c} {} "libzlibfoo.so"}
  57. {"Build libgnufoo.so with zlib-gnu compressed debug sections"
  58. "-shared -Wl,--compress-debug-sections=zlib-gnu"
  59. "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
  60. {foo.c} {} "libgnufoo.so"}
  61. {"Build libgabifoo.so with zlib-gabi compressed debug sections"
  62. "-shared -Wl,--compress-debug-sections=zlib-gabi"
  63. "-fPIC -ggdb3 -Wa,--compress-debug-sections=zlib-gabi"
  64. {foo.c} {} "libgabifoo.so"}
  65. {"Build zlibbegin.o with zlib compressed debug sections"
  66. "-r -nostdlib -Wl,--compress-debug-sections=zlib"
  67. "-ggdb3 -Wa,--compress-debug-sections=zlib"
  68. {begin.c} {} "zlibbegin.o"}
  69. {"Build gnubegin.o with zlib-gnu compressed debug sections"
  70. "-r -nostdlib -Wl,--compress-debug-sections=zlib-gnu"
  71. "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
  72. {begin.c} {} "gnubegin.o"}
  73. {"Build gabiend.o with zlib-gabi compressed debug sections"
  74. "-r -nostdlib -Wl,--compress-debug-sections=zlib-gabi"
  75. "-ggdb3 -Wa,--compress-debug-sections=zlib-gnu"
  76. {end.c} {} "gabiend.o"}
  77. }
  78. set run_tests {
  79. {"Run normal with libfoo.so with compressed debug sections"
  80. "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" ""
  81. {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections"}
  82. {"Run normal with libfoozlib.so with compressed debug sections with zlib-gabi"
  83. "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o" ""
  84. {main.c} "normal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
  85. {"Run zlibnormal with libzlibfoo.so with zlib compressed debug sections"
  86. "tmpdir/begin.o tmpdir/libzlibfoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" ""
  87. {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"}
  88. {"Run zlibnormal with libfoozlib.so with zlib compressed debug sections"
  89. "tmpdir/begin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib" ""
  90. {main.c} "zlibnormal" "normal.out" "-Wa,--compress-debug-sections=zlib"}
  91. {"Run gnunormal with libgnufoo.so with zlib-gnu compressed debug sections"
  92. "tmpdir/gnubegin.o tmpdir/libgnufoo.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" ""
  93. {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"}
  94. {"Run gnunormal with libfoozlib.so with zlib-gnu compressed debug sections"
  95. "tmpdir/gnubegin.o tmpdir/libfoozlib.so tmpdir/end.o -Wl,--compress-debug-sections=zlib-gnu" ""
  96. {main.c} "gnunormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gnu"}
  97. {"Run gabinormal with libgabifoo.so with zlib-gabi compressed debug sections"
  98. "tmpdir/zlibbegin.o tmpdir/libgabifoo.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" ""
  99. {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
  100. {"Run gabinormal with libfoozlib.so with zlib-gabi compressed debug sections"
  101. "tmpdir/zlibbegin.o tmpdir/libfoozlib.so tmpdir/gabiend.o -Wl,--compress-debug-sections=zlib-gabi" ""
  102. {main.c} "gabinormal" "normal.out" "-Wa,--compress-debug-sections=zlib-gabi"}
  103. }
  104. run_cc_link_tests $build_tests
  105. run_ld_link_exec_tests $run_tests
  106. set test_name "Link with zlib-gabi compressed debug input"
  107. send_log "cmp tmpdir/libfoo.so tmpdir/libfoozlib.so\n"
  108. if { [catch {exec cmp tmpdir/libfoo.so tmpdir/libfoozlib.so}] } then {
  109. send_log "tmpdir/libfoo.so tmpdir/libfoozlib.so differ.\n"
  110. fail "$test_name"
  111. } else {
  112. pass "$test_name"
  113. }
  114. set test_name "Link -r with zlib compressed debug output"
  115. set test zlibbegin
  116. send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n"
  117. set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
  118. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  119. send_log "$got\n"
  120. fail "$test_name"
  121. }
  122. if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
  123. fail "$test_name"
  124. } else {
  125. pass "$test_name"
  126. }
  127. set test_name "Link -r with zlib-gnu compressed debug output"
  128. set test gnubegin
  129. send_log "$READELF -S -W tmpdir/$test.o > tmpdir/$test.out\n"
  130. set got [remote_exec host "$READELF -S -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
  131. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  132. send_log "$got\n"
  133. fail "$test_name"
  134. }
  135. if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
  136. fail "$test_name"
  137. } else {
  138. pass "$test_name"
  139. }
  140. set test_name "Link -r with zlib-gabi compressed debug output"
  141. set test gabiend
  142. send_log "$READELF -t -W tmpdir/$test.o > tmpdir/$test.out\n"
  143. set got [remote_exec host "$READELF -t -W tmpdir/$test.o" "" "/dev/null" "tmpdir/$test.out"]
  144. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  145. send_log "$got\n"
  146. fail "$test_name"
  147. }
  148. if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then {
  149. fail "$test_name"
  150. } else {
  151. pass "$test_name"
  152. }
  153. set test_name "Link with zlib compressed debug output 1"
  154. set test normal
  155. send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n"
  156. set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"]
  157. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  158. send_log "$got\n"
  159. fail "$test_name"
  160. }
  161. set test_name "Link with zlib compressed debug output 2"
  162. set test zlibnormal
  163. send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n"
  164. set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"]
  165. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  166. send_log "$got\n"
  167. fail "$test_name"
  168. }
  169. if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
  170. send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
  171. fail "$test_name"
  172. } else {
  173. pass "$test_name"
  174. }
  175. set test_name "Link with zlib compressed debug output 3"
  176. send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n"
  177. set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
  178. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  179. send_log "$got\n"
  180. fail "$test_name"
  181. }
  182. if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
  183. fail "$test_name"
  184. } else {
  185. pass "$test_name"
  186. }
  187. set test_name "Link with zlib-gnu compressed debug output 1"
  188. set test gnunormal
  189. send_log "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out\n"
  190. set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test | sed -e \"s/.zdebug_/.debug_/\" > tmpdir/$test.out"]] "" "/dev/null"]
  191. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  192. send_log "$got\n"
  193. fail "$test_name"
  194. }
  195. if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
  196. send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
  197. fail "$test_name"
  198. } else {
  199. pass "$test_name"
  200. }
  201. set test_name "Link with zlib-gnu compressed debug output 2"
  202. send_log "$READELF -S -W tmpdir/$test' > tmpdir/$test.out\n"
  203. set got [remote_exec host "$READELF -S -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
  204. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  205. send_log "$got\n"
  206. fail "$test_name"
  207. }
  208. if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rS] } then {
  209. fail "$test_name"
  210. } else {
  211. pass "$test_name"
  212. }
  213. set test gabinormal
  214. set test_name "Link with zlib-gabi compressed debug output 1"
  215. send_log "$READELF -w tmpdir/$test > tmpdir/$test.out\n"
  216. set got [remote_exec host [concat sh -c [list "$READELF -w tmpdir/$test > tmpdir/$test.out"]] "" "/dev/null"]
  217. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  218. send_log "$got\n"
  219. fail "$test_name"
  220. }
  221. if { [catch {exec cmp tmpdir/normal.out tmpdir/$test.out}] } then {
  222. send_log "tmpdir/normal.out tmpdir/$test.out differ.\n"
  223. fail "$test_name"
  224. } else {
  225. pass "$test_name"
  226. }
  227. set test_name "Link with zlib-gabi compressed debug output 2"
  228. send_log "$READELF -t -W tmpdir/$test > tmpdir/$test.out\n"
  229. set got [remote_exec host "$READELF -t -W tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
  230. if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
  231. send_log "$got\n"
  232. fail "$test_name"
  233. }
  234. if { [regexp_diff tmpdir/$test.out $srcdir/$subdir/$test.rt] } then {
  235. fail "$test_name"
  236. } else {
  237. pass "$test_name"
  238. }