vsb.exp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. # Expect script for ld-visibility tests
  2. # Copyright (C) 2000-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. # Written by Ian Lance Taylor (ian@cygnus.com)
  22. # and H.J. Lu (hjl@gnu.org)
  23. #
  24. # Make sure that ld can generate ELF shared libraries with visibility.
  25. # Check to see if the C compiler works
  26. if { ![check_compiler_available] } {
  27. return
  28. }
  29. # This test can only be run on a couple of ELF platforms or with
  30. # XCOFF formats.
  31. # Square bracket expressions seem to confuse istarget.
  32. if { ![istarget hppa*64*-*-hpux*] \
  33. && ![istarget hppa*-*-linux*] \
  34. && ![istarget i?86-*-linux*] \
  35. && ![istarget i?86-*-gnu*] \
  36. && ![istarget *-*-nacl*] \
  37. && ![istarget ia64-*-linux*] \
  38. && ![istarget m68k-*-linux*] \
  39. && ![istarget mips*-*-linux*] \
  40. && ![istarget powerpc*-*-linux*] \
  41. && ![istarget arm*-*-linux*] \
  42. && ![istarget alpha*-*-linux*] \
  43. && ![istarget sparc*-*-linux*] \
  44. && ![istarget s390*-*-linux*] \
  45. && ![istarget sh\[34\]*-*-linux*] \
  46. && ![istarget x86_64-*-linux*] \
  47. && ![is_xcoff_format] } {
  48. return
  49. }
  50. if [is_xcoff_format] {
  51. set test_list [lsort [glob -nocomplain $srcdir/$subdir/*-xcoff*.d]]
  52. } else {
  53. set test_list [lsort [glob -nocomplain $srcdir/$subdir/*-elf.d]]
  54. }
  55. foreach t $test_list {
  56. # We need to strip the ".d", but can leave the dirname.
  57. verbose [file rootname $t]
  58. run_dump_test [file rootname $t]
  59. }
  60. set tmpdir tmpdir
  61. set SHCFLAG ""
  62. set shared_needs_pic "no"
  63. set COMPRESS_LDFLAG "-Wl,--compress-debug-sections=zlib-gabi"
  64. if { [is_xcoff_format] } {
  65. # Not all the useful features are available with AIX shared
  66. # libraries by default.
  67. # We can manage to simulate some of them with export/import
  68. # files but the overriding of shared library functions or
  69. # variables by the main program doesn't seem possible.
  70. # We avoid testing those features.
  71. set SHCFLAG "-DXCOFF_TEST"
  72. # In order to avoid listing every symbols in an export file,
  73. # the export will be done with -bexpall flag.
  74. # However for imports, we must create the import file.
  75. set file [open $tmpdir/xcoff-shared.imp w]
  76. puts $file "#! ."
  77. puts $file mainvar
  78. puts $file main_called
  79. close $file
  80. # XCOFF doesn't yet support debug sections compresion.
  81. set COMPRESS_LDFLAG ""
  82. }
  83. if [istarget arm*-*-linux*] {
  84. # On ARM section anchors can change the symbol pre-emptability for
  85. # non-PIC shared libraries, causing these tests to fail. Turn section
  86. # anchors off.
  87. set SHCFLAG "-fno-section-anchors"
  88. # On targets that have MOVW the compiler will emit relocations which
  89. # the linker doesn't support when compiling -shared without -fpic. The
  90. # test to find out whether we want to XFAIL the non-PIC tests requires
  91. # a compile - so we pre-calculate it here. We also note that this can
  92. # only affect arm*-*-*eabi* targets as the old ABI doesn't support v7.
  93. if [istarget arm*-*-*eabi*] {
  94. set file [open $tmpdir/movw-detect.c w]
  95. puts $file "void foo(void) { __asm (\"movw r0, #0\"); }"
  96. close $file
  97. if [run_host_cmd_yesno "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
  98. set shared_needs_pic "yes"
  99. }
  100. }
  101. }
  102. set support_protected "no"
  103. if { [istarget *-*-linux*]
  104. || [istarget *-*-nacl*]
  105. || [istarget *-*-gnu*] } {
  106. if [ld_compile "$CC_FOR_TARGET -g -DPROTECTED_CHECK" $srcdir/$subdir/main.c $tmpdir/main.o] {
  107. if [ld_link $CC_FOR_TARGET $tmpdir/main "$tmpdir/main.o"] {
  108. catch "exec $tmpdir/main" support_protected
  109. }
  110. }
  111. }
  112. # The test procedure.
  113. proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
  114. global CC_FOR_TARGET
  115. global srcdir
  116. global subdir
  117. global exec_output
  118. global link_output
  119. global host_triplet
  120. global tmpdir
  121. if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
  122. # Build the shared library.
  123. set shared -shared
  124. if { [is_xcoff_format] } {
  125. # On AIX, setup imports and exports.
  126. append shared " -Wl,-bexpall -Wl,-bI:$tmpdir/xcoff-shared.imp"
  127. }
  128. if { [is_elf_format] && [check_shared_lib_support] } {
  129. append shared " -Wl,-z,notext"
  130. }
  131. if {![ld_link $CC_FOR_TARGET $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
  132. if { [ string match $visibility "hidden_undef" ]
  133. && [regexp "undefined reference to \`\.?visibility\'" $link_output]
  134. && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
  135. pass "$testname"
  136. } else { if { [ string match $visibility "protected_undef" ]
  137. && [regexp "undefined reference to \`\.?visibility\'" $link_output]
  138. && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
  139. pass "$testname"
  140. } else {
  141. fail "$testname"
  142. }}
  143. return
  144. }
  145. # Link against the shared library. Use -rpath so that the
  146. # dynamic linker can locate the shared library at runtime.
  147. # On AIX, we must include /lib in -rpath, as otherwise the loader
  148. # can not find -lc.
  149. set rpath $tmpdir
  150. set exportflag ""
  151. if { [is_xcoff_format] } {
  152. set rpath /lib:$tmpdir
  153. set exportflag " -Wl,-bexpall"
  154. }
  155. if ![ld_link $CC_FOR_TARGET $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so $exportflag"] {
  156. if { [ string match $visibility "hidden" ]
  157. && [regexp "undefined reference to \`\.?visibility\'" $link_output]
  158. && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
  159. pass "$testname"
  160. } else { if { [ string match $visibility "hidden_undef_def" ]
  161. && [regexp "undefined reference to \`\.?visibility\'" $link_output]
  162. && [regexp "undefined reference to \`visibility_def\'" $link_output]
  163. && [regexp "undefined reference to \`\.?visibility_func\'" $link_output]
  164. && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
  165. pass "$testname"
  166. } else {
  167. fail "$testname"
  168. }}
  169. return
  170. }
  171. if { [ string match $visibility "hidden" ]
  172. || [ string match $visibility "hidden_undef" ]
  173. || [ string match $visibility "protected_undef" ] } {
  174. fail "$testname"
  175. }
  176. if ![isnative] {
  177. unsupported "$testname"
  178. return
  179. }
  180. # Run the resulting program
  181. send_log "$tmpdir/$progname >$tmpdir/$progname.out\n"
  182. verbose "$tmpdir/$progname >$tmpdir/$progname.out"
  183. catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
  184. if ![string match "" $exec_output] then {
  185. send_log "$exec_output\n"
  186. verbose "$exec_output"
  187. fail "$testname"
  188. return
  189. }
  190. send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
  191. verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
  192. catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
  193. set exec_output [prune_warnings $exec_output]
  194. if {![string match "" $exec_output]} then {
  195. send_log "$exec_output\n"
  196. verbose "$exec_output"
  197. fail "$testname"
  198. return
  199. }
  200. pass "$testname"
  201. }
  202. proc visibility_run {visibility} {
  203. global CC_FOR_TARGET
  204. global SHCFLAG
  205. global srcdir
  206. global subdir
  207. global tmpdir
  208. global picflag
  209. global target_triplet
  210. global support_protected
  211. global shared_needs_pic
  212. global PLT_CFLAGS
  213. global NOPIE_CFLAGS
  214. global COMPRESS_LDFLAG
  215. global NOSANITIZE_CFLAGS
  216. global NOLTO_CFLAGS
  217. if [ string match $visibility "hidden" ] {
  218. set VSBCFLAG "-DHIDDEN_TEST"
  219. } else { if [ string match $visibility "hidden_normal" ] {
  220. set VSBCFLAG "-DHIDDEN_NORMAL_TEST"
  221. } else { if [ string match $visibility "hidden_undef" ] {
  222. set VSBCFLAG "-DHIDDEN_UNDEF_TEST"
  223. } else { if [ string match $visibility "hidden_undef_def" ] {
  224. set VSBCFLAG "-DHIDDEN_UNDEF_TEST -DDSO_DEFINE_TEST"
  225. } else { if [ string match $visibility "hidden_weak" ] {
  226. set VSBCFLAG "-DHIDDEN_WEAK_TEST"
  227. } else { if [ string match $visibility "protected" ] {
  228. set VSBCFLAG "-DPROTECTED_TEST"
  229. } else { if [ string match $visibility "protected_undef" ] {
  230. set VSBCFLAG "-DPROTECTED_UNDEF_TEST"
  231. } else { if [ string match $visibility "protected_undef_def" ] {
  232. set VSBCFLAG "-DPROTECTED_UNDEF_TEST -DDSO_DEFINE_TEST"
  233. } else { if [ string match $visibility "protected_weak" ] {
  234. set VSBCFLAG "-DPROTECTED_WEAK_TEST"
  235. } else {
  236. set VSBCFLAG ""
  237. }}}}}}}}}
  238. # Ensure we always start with a clean slate, for the "file exists"
  239. # tests below.
  240. remote_file host delete $tmpdir/sh1p.o $tmpdir/sh2p.o $tmpdir/sh1np.o $tmpdir/sh2np.o
  241. set datfile elfvsb
  242. if { [is_xcoff_format] } {
  243. # As explained above, XCOFF shared libraries doesn't support
  244. # all the ELF features. Thus, the output of the tests are
  245. # a bit different.
  246. set datfile xcoffvsb
  247. }
  248. if { [istarget powerpc*-*-linux*] \
  249. || ( [istarget mips*-*-linux*] && [at_least_gcc_version 4 3] )} {
  250. # Testing non-PIC libraries is a waste of effort on any target.
  251. # If you don't pass -fpic or -fPIC to gcc, gcc will assume quite
  252. # reasonably that you are not compiling for a shared library.
  253. # It can then make optimisations that result in shared library
  254. # functions and variables not being overridable. Newer versions
  255. # of gcc are more likely to do this.
  256. } else {
  257. # Compile the main program. Make sure that PLT is used since PLT
  258. # is expected.
  259. if ![ld_compile "$CC_FOR_TARGET -g $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
  260. unsupported "visibility ($visibility) (non PIC)"
  261. unsupported "visibility ($visibility)"
  262. } else {
  263. # The shared library is composed of two files. First compile them
  264. # without using -fpic. That should work on an ELF system,
  265. # although it will be less efficient because the dynamic linker
  266. # will need to do more relocation work. However, note that not
  267. # using -fpic will cause some of the tests to return different
  268. # results. Make sure that PLT is used since PLT is expected.
  269. if { ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
  270. || ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
  271. unsupported "visibility ($visibility) (non PIC)"
  272. } else {
  273. # SunOS non PIC shared libraries don't permit some cases of
  274. # overriding.
  275. if { [ string match $visibility "protected" ]
  276. || [ string match $visibility "protected_undef_def" ] } {
  277. if [ string match $support_protected "no" ] {
  278. setup_xfail $target_triplet
  279. }
  280. }
  281. # Non-pic code uses name binding rules for applications to
  282. # reference variables by gp-relative relocs, which can't be
  283. # used with overridable symbols.
  284. if { ![ string match $visibility "hidden_undef" ]
  285. && ![ string match $visibility "protected_undef" ] } {
  286. setup_xfail "ia64-*-linux*"
  287. setup_xfail "alpha*-*-linux*"
  288. }
  289. if { ![ string match $visibility "hidden" ]
  290. && ![ string match $visibility "hidden_undef" ]
  291. && ![ string match $visibility "hidden_undef_def" ]
  292. && ![ string match $visibility "protected_undef" ] } {
  293. setup_xfail "s390x-*-linux*"
  294. if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
  295. setup_xfail "sparc*-*-linux*"
  296. }
  297. }
  298. if { [is_elf64 $tmpdir/mainnp.o] } {
  299. setup_xfail "x86_64-*-linux*"
  300. }
  301. setup_xfail "x86_64-*-linux-gnux32"
  302. if { ![istarget hppa*64*-*-linux*] } {
  303. setup_xfail "hppa*-*-linux*"
  304. }
  305. if [ string match $shared_needs_pic "yes" ] {
  306. setup_xfail "arm*-*-linux*"
  307. }
  308. # XCOFF format doesn't know how to handle weak undefined symbols
  309. # in shared objects.
  310. if { [ string match $visibility "hidden_weak" ]
  311. || [ string match $visibility "protected_weak" ] } {
  312. setup_xfail "*-*-aix*"
  313. setup_xfail "*-*-beos*"
  314. }
  315. visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o $datfile
  316. # Test ELF shared library relocations with a non-zero load
  317. # address for the library. Near as I can tell, the R_*_RELATIVE
  318. # relocations for various targets are broken in the case where
  319. # the load address is not zero (which is the default).
  320. if { [ string match $visibility "protected" ]
  321. || [ string match $visibility "protected_undef_def" ] } {
  322. if [ string match $support_protected "no" ] {
  323. setup_xfail $target_triplet
  324. }
  325. }
  326. if { [ string match $visibility "hidden_normal" ]
  327. || [ string match $visibility "hidden_weak" ]
  328. || [ string match $visibility "protected" ]
  329. || [ string match $visibility "protected_undef_def" ]
  330. || [ string match $visibility "protected_weak" ]
  331. || [ string match $visibility "normal" ] } {
  332. setup_xfail "powerpc-*-linux*"
  333. setup_xfail "s390x-*-linux*"
  334. if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
  335. setup_xfail "sparc*-*-linux*"
  336. }
  337. }
  338. if { ![ string match $visibility "hidden_undef" ]
  339. && ![ string match $visibility "protected_undef" ] } {
  340. setup_xfail "ia64-*-linux*"
  341. setup_xfail "alpha*-*-linux*"
  342. setup_xfail "mips*-*-linux*"
  343. }
  344. if { [is_elf64 $tmpdir/mainnp.o] } {
  345. setup_xfail "x86_64-*-linux*"
  346. }
  347. setup_xfail "x86_64-*-linux-gnux32"
  348. if { ![istarget hppa*64*-*-linux*] } {
  349. setup_xfail "hppa*-*-linux*"
  350. }
  351. if [ string match $shared_needs_pic "yes" ] {
  352. setup_xfail "arm*-*-linux*"
  353. }
  354. # XCOFF format doesn't know how to handle weak undefined symbols
  355. # in shared objects.
  356. if { [ string match $visibility "hidden_weak" ]
  357. || [ string match $visibility "protected_weak" ] } {
  358. setup_xfail "*-*-aix*"
  359. setup_xfail "*-*-beos*"
  360. }
  361. if { ![is_xcoff_format] } {
  362. visibility_test $visibility vnp "visibility ($visibility) (non PIC, load offset)" \
  363. mainnp.o sh1np.o sh2np.o $datfile \
  364. "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv"
  365. }
  366. }
  367. # Now compile the code using -fpic.
  368. if { ![ld_compile "$CC_FOR_TARGET -g $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS -DSHARED $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
  369. || ![ld_compile "$CC_FOR_TARGET -g $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS -DSHARED $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
  370. unsupported "visibility ($visibility)"
  371. } else {
  372. if { [ string match $visibility "protected" ]
  373. || [ string match $visibility "protected_undef_def" ] } {
  374. if [ string match $support_protected "no" ] {
  375. setup_xfail $target_triplet
  376. }
  377. }
  378. visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o $datfile $COMPRESS_LDFLAG
  379. }
  380. }}
  381. if { [istarget powerpc*-*-linux*] } {
  382. # Don't bother.
  383. } else {
  384. # Now do the same tests again, but this time compile main.c PIC.
  385. if ![ld_compile "$CC_FOR_TARGET -g $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS -DSHARED $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
  386. unsupported "visibility ($visibility) (PIC main, non PIC so)"
  387. unsupported "visibility ($visibility) (PIC main)"
  388. } else {
  389. if { [ remote_file host exists $tmpdir/sh1np.o ]
  390. && [ remote_file host exists $tmpdir/sh2np.o ] } {
  391. # SunOS non PIC shared libraries don't permit some cases of
  392. # overriding.
  393. if { [ string match $visibility "protected" ]
  394. || [ string match $visibility "protected_undef_def" ] } {
  395. if [ string match $support_protected "no" ] {
  396. setup_xfail $target_triplet
  397. }
  398. }
  399. if { ![ string match $visibility "hidden_undef" ]
  400. && ![ string match $visibility "protected_undef" ] } {
  401. setup_xfail "ia64-*-linux*"
  402. setup_xfail "alpha*-*-linux*"
  403. }
  404. if { ![ string match $visibility "hidden" ]
  405. && ![ string match $visibility "hidden_undef" ]
  406. && ![ string match $visibility "hidden_undef_def" ]
  407. && ![ string match $visibility "protected_undef" ] } {
  408. setup_xfail "s390x-*-linux*"
  409. if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } {
  410. setup_xfail "sparc*-*-linux*"
  411. }
  412. }
  413. if { [is_elf64 $tmpdir/mainp.o] } {
  414. setup_xfail "x86_64-*-linux*"
  415. }
  416. setup_xfail "x86_64-*-linux-gnux32"
  417. if { ![istarget hppa*64*-*-linux*] } {
  418. setup_xfail "hppa*-*-linux*"
  419. }
  420. if [ string match $shared_needs_pic "yes" ] {
  421. setup_xfail "arm*-*-linux*"
  422. }
  423. # XCOFF format doesn't know how to handle weak undefined symbols
  424. # in shared objects.
  425. if { [ string match $visibility "hidden_weak" ]
  426. || [ string match $visibility "protected_weak" ] } {
  427. setup_xfail "*-*-aix*"
  428. setup_xfail "*-*-beos*"
  429. }
  430. visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o $datfile
  431. } else {
  432. unsupported "visibility (PIC main, non PIC so)"
  433. }
  434. if { [ remote_file host exists $tmpdir/sh1p.o ]
  435. && [ remote_file host exists $tmpdir/sh2p.o ] } {
  436. if { [ string match $visibility "protected" ]
  437. || [ string match $visibility "protected_undef_def" ] } {
  438. if [ string match $support_protected "no" ] {
  439. setup_xfail $target_triplet
  440. }
  441. }
  442. # XCOFF format doesn't know how to handle weak undefined symbols
  443. # in shared objects.
  444. if { [ string match $visibility "hidden_weak" ]
  445. || [ string match $visibility "protected_weak" ] } {
  446. setup_xfail "*-*-aix*"
  447. setup_xfail "*-*-beos*"
  448. }
  449. visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o $datfile
  450. } else {
  451. unsupported "visibility ($visibility) (PIC main)"
  452. }
  453. }}
  454. }
  455. # Old version of GCC for MIPS default to enabling -fpic
  456. # and get confused if it is used on the command line.
  457. if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
  458. set picflag ""
  459. } else {
  460. # Unfortunately, the gcc argument is -fpic and the cc argument is
  461. # -KPIC. We have to try both.
  462. set picflag "-fpic"
  463. send_log "$CC_FOR_TARGET $picflag\n"
  464. verbose "$CC_FOR_TARGET $picflag"
  465. catch "exec $CC_FOR_TARGET $picflag" exec_output
  466. send_log "$exec_output\n"
  467. verbose "--" "$exec_output"
  468. if { [string match "*illegal option*" $exec_output] \
  469. || [string match "*option ignored*" $exec_output] \
  470. || [string match "*unrecognized option*" $exec_output] \
  471. || [string match "*passed to ld*" $exec_output] } {
  472. set picflag "-KPIC"
  473. }
  474. }
  475. verbose "Using $picflag to compile PIC code"
  476. visibility_run hidden
  477. visibility_run hidden_normal
  478. visibility_run hidden_undef
  479. visibility_run hidden_undef_def
  480. visibility_run hidden_weak
  481. visibility_run protected
  482. visibility_run protected_undef
  483. visibility_run protected_undef_def
  484. visibility_run protected_weak
  485. visibility_run normal
  486. if { ![ld_compile "$CC_FOR_TARGET -g $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/common.c tmpdir/common.o] } {
  487. unsupported "common hidden symbol"
  488. } else {
  489. if ![ld_link $ld tmpdir/common "tmpdir/common.o"] {
  490. fail "common hidden symbol"
  491. } else {
  492. pass "common hidden symbol"
  493. }
  494. }
  495. if { ![ld_compile "$CC_FOR_TARGET -g $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/test.c tmpdir/test.o] } {
  496. unsupported "weak hidden symbol"
  497. } else {
  498. if { ![ld_compile "$CC_FOR_TARGET -g $NOSANITIZE_CFLAGS $NOLTO_CFLAGS -DSHARED $picflag" $srcdir/$subdir/sh3.c tmpdir/sh3.o] } {
  499. unsupported "weak hidden symbol"
  500. } else {
  501. set shared "-shared"
  502. if { [is_xcoff_format] } {
  503. # On AIX, setup imports and exports.
  504. append shared " -bexpall"
  505. }
  506. if ![ld_link $ld tmpdir/sh3.so "$shared tmpdir/sh3.o"] {
  507. fail "weak hidden symbol"
  508. } else {
  509. if ![ld_link $ld tmpdir/weak "tmpdir/test.o tmpdir/sh3.so"] {
  510. fail "weak hidden symbol DSO last"
  511. } else {
  512. pass "weak hidden symbol DSO last"
  513. }
  514. if ![ld_link $ld tmpdir/weak "tmpdir/sh3.so tmpdir/test.o"] {
  515. fail "weak hidden symbol DSO first"
  516. } else {
  517. pass "weak hidden symbol DSO first"
  518. }
  519. }
  520. }
  521. }