exclude.exp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Expect script for --exclude-libs tests
  2. # Copyright (C) 2004-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. # Make sure that ld can hide symbols from libraries when building a shared
  21. # library.
  22. # This test can only be run on ELF platforms.
  23. if ![is_elf_format] {
  24. return
  25. }
  26. # No shared lib support on this target.
  27. if { [istarget "mcore-*-*"] } {
  28. return
  29. }
  30. set as_opt ""
  31. # This target requires extra as options when building code for shared
  32. # libraries.
  33. if { [istarget "tic6x-*-*"] } {
  34. set as_opt "-mpic -mpid=near"
  35. }
  36. set test1 "ld link shared library"
  37. set test2 "ld export symbols from archive"
  38. set test3 "ld link shared library with --exclude-libs"
  39. set test4 "ld exclude symbols from archive - --exclude-libs libexclude"
  40. set test5 "ld exclude symbols from archive - --exclude-libs libexclude.a"
  41. set test6 "ld exclude symbols from archive - --exclude-libs ALL"
  42. set test7 "ld exclude symbols from archive - --exclude-libs foo:libexclude.a"
  43. set test8 "ld exclude symbols from archive - --exclude-libs foo,libexclude.a"
  44. set test9 "ld don't exclude symbols from archive - --exclude-libs foo:bar"
  45. if { ![ld_assemble_flags $as $as_opt $srcdir/$subdir/exclude1.s tmpdir/exclude1.o ]
  46. || ![ld_assemble_flags $as $as_opt $srcdir/$subdir/exclude2.s tmpdir/exclude2.o] } {
  47. unsupported $test1
  48. return
  49. }
  50. remote_file host delete "tmpdir/libexclude.a"
  51. set catch_output [run_host_cmd "$ar" "cq tmpdir/libexclude.a tmpdir/exclude2.o"]
  52. if {![string match "" $catch_output]} {
  53. fail $test1
  54. return
  55. }
  56. # Test that the symbol is normally exported.
  57. if { [ld_link $ld tmpdir/exclude.so "--shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } {
  58. pass $test1
  59. } else {
  60. if [string match "*shared not supported*" $link_output] {
  61. unsupported "$test1 - -shared is not supported by this target"
  62. } else {
  63. fail $test1
  64. }
  65. return
  66. }
  67. if { [ld_nm $nm "-D" tmpdir/exclude.so]
  68. && [info exists nm_output(exclude_common)]
  69. && [info exists nm_output(exclude_sym)] } {
  70. pass $test2
  71. } else {
  72. fail $test2
  73. }
  74. # Test --exclude-libs libexclude
  75. if { [ld_link $ld tmpdir/exclude.so "--exclude-libs libexclude --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } {
  76. pass $test3
  77. } else {
  78. fail $test3
  79. }
  80. if { [ld_nm $nm "-D" tmpdir/exclude.so]
  81. && ! [info exists nm_output(exclude_common)]
  82. && ! [info exists nm_output(exclude_sym)] } {
  83. pass $test4
  84. } else {
  85. fail $test4
  86. }
  87. # Test alternate spellings of --exclude-libs
  88. if { [ld_link $ld tmpdir/exclude.so "--exclude-libs libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
  89. && [ld_nm $nm "-D" tmpdir/exclude.so]
  90. && ! [info exists nm_output(exclude_common)]
  91. && ! [info exists nm_output(exclude_sym)] } {
  92. pass $test5
  93. } else {
  94. fail $test5
  95. }
  96. if { [ld_link $ld tmpdir/exclude.so "--exclude-libs ALL --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
  97. && [ld_nm $nm "-D" tmpdir/exclude.so]
  98. && ! [info exists nm_output(exclude_common)]
  99. && ! [info exists nm_output(exclude_sym)] } {
  100. pass $test6
  101. } else {
  102. fail $test6
  103. }
  104. if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo:libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
  105. && [ld_nm $nm "-D" tmpdir/exclude.so]
  106. && ! [info exists nm_output(exclude_common)]
  107. && ! [info exists nm_output(exclude_sym)] } {
  108. pass $test7
  109. } else {
  110. fail $test7
  111. }
  112. if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo,libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
  113. && [ld_nm $nm "-D" tmpdir/exclude.so]
  114. && ! [info exists nm_output(exclude_common)]
  115. && ! [info exists nm_output(exclude_sym)] } {
  116. pass $test8
  117. } else {
  118. fail $test8
  119. }
  120. if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo:bar --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
  121. && [ld_nm $nm "-D" tmpdir/exclude.so]
  122. && [info exists nm_output(exclude_common)]
  123. && [info exists nm_output(exclude_sym)] } {
  124. pass $test9
  125. } else {
  126. fail $test9
  127. }