shared.exp 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. # Expect script for various ELF tests.
  2. # Copyright (C) 2006-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. set old_ASFLAGS $ASFLAGS
  30. # This target requires extra GAS options when building code for shared
  31. # libraries.
  32. set AFLAGS_PIC ""
  33. if [istarget "nds32*-*"] {
  34. append AFLAGS_PIC " -mpic"
  35. }
  36. if [istarget "tic6x-*-*"] {
  37. append AFLAGS_PIC " -mpic -mpid=near"
  38. }
  39. if [istarget "sparc*-*-*"] {
  40. append AFLAGS_PIC " -K PIC -Av9"
  41. }
  42. # GAS options to disable program property note.
  43. set AFLAGS_NOTE ""
  44. if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
  45. append AFLAGS_NOTE "-mx86-used-note=no"
  46. }
  47. # This target requires a non-default emulation for successful shared
  48. # library/executable builds.
  49. set LFLAGS ""
  50. if [istarget "tic6x-*-*"] {
  51. append LFLAGS " -melf32_tic6x_le"
  52. }
  53. # HPUX targets use a different .comm syntax.
  54. set hpux ""
  55. if [istarget "*-*-hpux*"] {
  56. set hpux "--defsym HPUX=1"
  57. }
  58. # These targets do not default to linking with shared libraries.
  59. if { [istarget "mips*vr4100*-*-elf*"] \
  60. || [istarget "mips*vr4300*-*-elf*"] \
  61. || [istarget "mips*vr5000*-*-elf*"] } {
  62. append LFLAGS " -call_shared"
  63. }
  64. if [is_underscore_target] {
  65. append ASFLAGS " --defsym UNDERSCORE=1"
  66. }
  67. run_ld_link_tests [list \
  68. [list \
  69. "Build pr22471a.so" \
  70. "$LFLAGS -shared" \
  71. "" \
  72. "$AFLAGS_PIC" \
  73. {pr22471a.s} \
  74. {} \
  75. "pr22471a.so" \
  76. ] \
  77. [list \
  78. "Build pr22471b.so" \
  79. "$LFLAGS -shared --version-script pr22471.t" \
  80. "tmpdir/pr22471a.so" \
  81. "$AFLAGS_PIC" \
  82. {pr22471a.s} \
  83. {} \
  84. "pr22471b.so" \
  85. ] \
  86. [list \
  87. "Build pr22649-1.so" \
  88. "$LFLAGS -shared" \
  89. "" \
  90. "$AFLAGS_PIC" \
  91. {pr22649-1.s} \
  92. {} \
  93. "pr22649-1.so" \
  94. ] \
  95. ]
  96. run_ld_link_tests [list \
  97. [list \
  98. "Build pr22471" \
  99. "$LFLAGS -rpath-link . -rpath-link tmpdir" \
  100. "tmpdir/pr22471b.so" \
  101. "" \
  102. {pr22471b.s} \
  103. {} \
  104. "pr22471" \
  105. ] \
  106. ] bfin-*-* frv-*-* lm32-*-*
  107. if { [check_gc_sections_available] } {
  108. if [istarget mips*-*-*] {
  109. set actions {{ld pr22649-2ab-mips.msg}}
  110. } else {
  111. set actions {{ld pr22649.msg}}
  112. }
  113. run_ld_link_tests [list \
  114. [list \
  115. "Build pr22649-2a.so" \
  116. "$LFLAGS -shared -gc-sections -print-gc-sections" \
  117. "" \
  118. "$AFLAGS_PIC" \
  119. {pr22649-2a.s} \
  120. $actions \
  121. "pr22649-2a.so" \
  122. ] \
  123. [list \
  124. "Build pr22649-2b.so" \
  125. "$LFLAGS -shared -gc-sections -print-gc-sections" \
  126. "tmpdir/pr22649-1.so" \
  127. "$AFLAGS_PIC" \
  128. {pr22649-2a.s} \
  129. $actions \
  130. "pr22649-2b.so" \
  131. ] \
  132. ]
  133. if { [istarget mips*-*-*] && ![istarget *-*-elf*] } {
  134. set actions {{ld pr22649-2cd-mips.msg}}
  135. } else {
  136. set actions {}
  137. }
  138. run_ld_link_tests [list \
  139. [list \
  140. "Build pr22649-2c.so" \
  141. "$LFLAGS -shared -gc-sections -print-gc-sections" \
  142. "" \
  143. "$AFLAGS_PIC" \
  144. {pr22649-2b.s} \
  145. $actions \
  146. "pr22649-2b.so" \
  147. ] \
  148. [list \
  149. "Build pr22649-2d.so" \
  150. "$LFLAGS -shared -gc-sections -print-gc-sections" \
  151. "tmpdir/pr22649-1.so" \
  152. "$AFLAGS_PIC" \
  153. {pr22649-2b.s} \
  154. $actions \
  155. "pr22649-2b.so" \
  156. ] \
  157. ]
  158. }
  159. run_ld_link_tests [list \
  160. [list \
  161. "DT_TEXTREL in shared lib" \
  162. "$LFLAGS -shared --warn-shared-textrel" \
  163. "" \
  164. "$AFLAGS_PIC" \
  165. {textrel.s} \
  166. {{ld textrel.warn} \
  167. {readelf {-d --wide} textrel.rd}} \
  168. "textrel.so" \
  169. ] \
  170. ] bfin-*-* frv-*-* lm32-*-* xtensa-*-*
  171. # The MIPS backend sets SHF_WRITE, in `mips_elf_create_dynamic_relocation',
  172. # for any section that has a dynamic relocation attached and consequently
  173. # this test is irrelevant for MIPS targets. We don't have a clean way to
  174. # request UNSUPPORTED result, which would be the most appropriate here,
  175. # so we just XFAIL the test instead.
  176. run_ld_link_tests [list \
  177. [list \
  178. "DT_TEXTREL map file warning" \
  179. "$LFLAGS -shared -M" \
  180. "" \
  181. "$AFLAGS_PIC" \
  182. {textrel.s} \
  183. {{ld textrel.map}} \
  184. "textrel.so" \
  185. ] \
  186. ] bfin-*-* cris*-*-* frv-*-* lm32-*-* mips*-*-*
  187. # PR ld/20828 check for correct dynamic symbol table entries where:
  188. # - symbols have been defined with a linker script,
  189. # - the same symbols have been seen in shared library used in the link,
  190. # - the shared library symbols have been swept in section garbage collection.
  191. # Verify that the symbols are global rather than local and that a version
  192. # script adjusts them accordingly.
  193. # Also verify that a version definition supplied by an object rather than
  194. # a version script and forcibly exported is unaffected by section GC.
  195. if { [check_gc_sections_available] } {
  196. run_ld_link_tests [list \
  197. [list \
  198. "PR ld/20828 dynamic symbols with section GC\
  199. (auxiliary shared library)" \
  200. "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
  201. {pr20828.s} \
  202. {{readelf --dyn-syms pr20828-a.sd} \
  203. {readelf --dyn-syms pr20828-b.sd}} \
  204. "libpr20828.so"] \
  205. [list \
  206. "PR ld/20828 dynamic symbols with section GC (plain)" \
  207. "$LFLAGS -shared --gc-sections -T pr20828.ld" \
  208. "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
  209. {pr20828.s} \
  210. {{readelf --dyn-syms pr20828-a.sd} \
  211. {readelf --dyn-syms pr20828-b.sd}} \
  212. "pr20828-1.so"] \
  213. [list \
  214. "PR ld/20828 dynamic symbols with section GC (version script)" \
  215. "$LFLAGS -shared --gc-sections -T pr20828.ld\
  216. --version-script=pr20828.ver" \
  217. "tmpdir/libpr20828.so" \
  218. "$AFLAGS_PIC" \
  219. {pr20828.s} \
  220. {{readelf --dyn-syms pr20828-b.sd} \
  221. {readelf --dyn-syms pr20828-c.sd}} \
  222. "pr20828-2.so"] \
  223. [list \
  224. "PR ld/20828 dynamic symbols with section GC\
  225. (versioned shared library)" \
  226. "$LFLAGS -shared --gc-sections -T pr20828.ld\
  227. --version-script=pr20828-v.ver" \
  228. "" "$AFLAGS_PIC" \
  229. {pr20828.s} \
  230. {{readelf --dyn-syms pr20828-c.sd} \
  231. {readelf --dyn-syms pr20828-d.sd} \
  232. {readelf --dyn-syms pr20828-e.sd}} \
  233. "libpr20828-v.so"] \
  234. [list \
  235. "PR ld/20828 dynamic symbols with section GC (versioned)" \
  236. "$LFLAGS -shared --gc-sections -T pr20828.ld\
  237. --version-script=pr20828-v.ver" \
  238. "tmpdir/libpr20828-v.so" \
  239. "$AFLAGS_PIC" \
  240. {pr20828.s} \
  241. {{readelf --dyn-syms pr20828-c.sd} \
  242. {readelf --dyn-syms pr20828-d.sd} \
  243. {readelf --dyn-syms pr20828-e.sd}} \
  244. "pr20828-v.so"] \
  245. [list \
  246. "PR ld/20828 forcibly exported symbol version without section GC" \
  247. "$LFLAGS --no-dynamic-linker -e foo -E -T pr20828-v.ld" "" "" \
  248. {pr20828-v.s} \
  249. {{objdump -p pr20828-v.od}} \
  250. "pr20828-v-1"] \
  251. [list \
  252. "PR ld/20828 forcibly exported symbol version with section GC" \
  253. "$LFLAGS --no-dynamic-linker -e foo --gc-sections -E -T pr20828-v.ld" "" "" \
  254. {pr20828-v.s} \
  255. {{objdump -p pr20828-v.od}} \
  256. "pr20828-v-2"]]
  257. }
  258. # PR ld/21233 check for correct dynamic symbol table entries where:
  259. # - a symbol has been defined in a shared library used in the link,
  260. # - the symbol has been referenced from a section swept in garbage collection,
  261. # - the symbol has also been forced to be entered in the output file as an
  262. # undefined symbol, either with a command-line option or a linker script
  263. # command.
  264. # Verify that the undefined symbol is global rather than local.
  265. if { [check_gc_sections_available] } {
  266. run_ld_link_tests [list \
  267. [list \
  268. "PR ld/21233 dynamic symbols with section GC\
  269. (auxiliary shared library)" \
  270. "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \
  271. {pr21233-l.s} \
  272. {{readelf --dyn-syms pr21233-l.sd}} \
  273. "libpr21233.so"]]
  274. run_ld_link_tests [list \
  275. [list \
  276. "PR ld/21233 dynamic symbols with section GC (--undefined)" \
  277. "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \
  278. "tmpdir/libpr21233.so" "" \
  279. {pr21233.s} \
  280. {{readelf --dyn-syms pr21233.sd}} \
  281. "pr21233-1"]]
  282. run_ld_link_tests [list \
  283. [list \
  284. "PR ld/21233 dynamic symbols with section GC (--require-defined)" \
  285. "$LFLAGS --gc-sections -e foo --require-defined=bar\
  286. -T pr21233.ld" \
  287. "tmpdir/libpr21233.so" "" \
  288. {pr21233.s} \
  289. {{readelf --dyn-syms pr21233.sd}} \
  290. "pr21233-2"]]
  291. run_ld_link_tests [list \
  292. [list \
  293. "PR ld/21233 dynamic symbols with section GC (EXTERN)" \
  294. "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \
  295. "tmpdir/libpr21233.so" "" \
  296. {pr21233.s} \
  297. {{readelf --dyn-syms pr21233.sd}} \
  298. "pr21233-3"]]
  299. }
  300. if { [check_gc_sections_available] } {
  301. run_ld_link_tests [list \
  302. [list \
  303. "Build pr22150.so" \
  304. "$LFLAGS -shared --version-script pr22150.ver" \
  305. "" \
  306. "$AFLAGS_PIC" \
  307. {pr22150a.s} \
  308. {} \
  309. "pr22150.so" \
  310. ] \
  311. [list \
  312. "Build pr22150" \
  313. "$LFLAGS -e _start --gc-sections" \
  314. "tmpdir/pr22150.so" \
  315. "" \
  316. {pr22150b.s} \
  317. {{readelf -V pr22150.vd}} \
  318. "pr22150" \
  319. ] \
  320. ]
  321. switch -glob $target_triplet {
  322. # exclude targets that don't support copy relocs
  323. bfin-*-* { }
  324. frv-*-* { }
  325. lm32-*-* { }
  326. mips*-*-* { }
  327. tic6x-*-* { }
  328. xtensa-*-* { }
  329. default {
  330. run_ld_link_tests [list \
  331. [list \
  332. "Build pr25458.so" \
  333. "$LFLAGS -shared --version-script=pr25458.map" \
  334. "" \
  335. "$AFLAGS_PIC" \
  336. {pr25458b.s} \
  337. {} \
  338. "pr25458.so" \
  339. ] \
  340. [list \
  341. "Build pr25458" \
  342. "$LFLAGS -e _start --gc-sections" \
  343. "tmpdir/pr25458.so" \
  344. "$AFLAGS_PIC" \
  345. {pr25458a.s} \
  346. {{readelf {--dyn-sym --wide} pr25458.rd}} \
  347. "pr25458" \
  348. ] \
  349. ]
  350. }
  351. }
  352. }
  353. set ASFLAGS $old_ASFLAGS
  354. run_ld_link_tests {
  355. {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
  356. }
  357. run_ld_link_tests [list \
  358. [list "Build shared library for pr14170" \
  359. "-shared" "" "$AFLAGS_PIC" "pr14170b.s" {} "pr14170.so" ] \
  360. ]
  361. # bfin does not currently support copy relocs.
  362. setup_xfail bfin-*-*
  363. clear_xfail bfin-*-linux*
  364. run_ld_link_tests [list \
  365. [list "PR ld/14170" \
  366. "$LFLAGS --no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" \
  367. $hpux \
  368. {pr14170c.s} { } "pr14170" ] \
  369. ]
  370. # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
  371. # Nor will hppa64 with dot-symbols.
  372. run_ld_link_tests [list \
  373. [list "PR ld/21703 shared" \
  374. "$LFLAGS -shared --allow-multiple-definition --version-script pr21703.ver\
  375. tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "$AFLAGS_PIC" \
  376. {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} \
  377. "pr21703.so" ] \
  378. ] \[is_generic\] hppa64-*-*
  379. # This target requires extra GAS options when building non-PIC code
  380. # for linking with shared libraries.
  381. set AFLAGS_NONPIC ""
  382. if [istarget "mips*-*-*"] {
  383. append AFLAGS_NONPIC " -call_nonpic"
  384. }
  385. # Run a test to check linking a shared library with a broken linker
  386. # script that accidentally marks dynamic sections as notes. The
  387. # resulting executable is not expected to work, but the linker
  388. # should not seg-fault whilst creating the binary.
  389. run_ld_link_tests [list \
  390. [list "Build shared library for broken linker script test" \
  391. "-shared --hash-style=sysv" "" "$AFLAGS_PIC" "note-3.s" \
  392. {} \
  393. "note-3.so" ] \
  394. [list "Link using broken linker script" \
  395. "$LFLAGS --script note-3.t tmpdir/note-3.so" "" "" "" \
  396. { { ld "note-3.l" } } \
  397. "a.out" ] \
  398. ]
  399. run_ld_link_tests [list \
  400. [list "Build pr17068.so" \
  401. "-shared" "" "$AFLAGS_PIC" \
  402. {pr17068d.s} {} "pr17068.so"] \
  403. [list "Build pr17068a.a" \
  404. "" "" "" \
  405. {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"] \
  406. [list "Build pr17068b.a" \
  407. "" "" "" \
  408. {pr17068b.s pr17068e.s} {} "pr17068b.a"] \
  409. ]
  410. # bfin does not currently support copy relocs.
  411. setup_xfail bfin-*-*
  412. clear_xfail bfin-*-linux*
  413. run_ld_link_tests {
  414. {"pr17068 link --as-needed lib in group"
  415. "$LFLAGS --as-needed --no-dynamic-linker"
  416. "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a\
  417. --end-group" ""
  418. {start.s pr17068.s} {} "pr17068"}
  419. }
  420. # Fails on MIPS because ABI trickery means that a NULL reloc is emitted.
  421. # Fails on bfin because relocations are not created.
  422. setup_xfail mips*-*-* bfin-*-*
  423. clear_xfail bfin-*-linux*
  424. run_ld_link_tests [list \
  425. [list "-Bsymbolic-functions" \
  426. "-shared -Bsymbolic-functions $NO_DT_RELR_LDFLAGS" \
  427. "" "$AFLAGS_PIC" \
  428. {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}} \
  429. "symbolic-func.so"] \
  430. ]
  431. run_ld_link_tests [list \
  432. [list "Build pr20995.so" \
  433. "-shared" "" "$AFLAGS_PIC" \
  434. {pr20995b.s} {} "pr20995.so"] \
  435. ]
  436. # These targets don't copy dynamic variables into .bss.
  437. setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
  438. # or don't have .data.rel.ro
  439. setup_xfail "hppa*64*-*-hpux*" "tic6x-*-*"
  440. # or complain about relocs in read-only sections
  441. setup_xfail frv-*-* lm32-*-*
  442. run_ld_link_tests [list \
  443. [list \
  444. "pr20995" \
  445. "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
  446. {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
  447. # xfail on targets that don't support GNU_RELRO.
  448. # For more details, please see discussions at:
  449. # https://sourceware.org/ml/binutils/2017-01/msg00441.html
  450. run_ld_link_tests [list \
  451. [list "Build pr20995-2.so" \
  452. "-shared -z relro" "" "$AFLAGS_PIC" \
  453. {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
  454. ] {![check_relro_support]}
  455. setup_xfail alpha-*-* xtensa-*-*
  456. run_ld_link_tests [list \
  457. [list \
  458. "pr20995-2" \
  459. "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
  460. {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]
  461. ] {![check_relro_support]}
  462. run_ld_link_tests [list \
  463. [list "Build pr22374 shared library" \
  464. "-shared" "" "$AFLAGS_PIC" "pr22374b.s" {} "pr22374.so" ] \
  465. ]
  466. # The next test checks that copy relocs are not used unnecessarily,
  467. # but that is just an optimization so don't complain loudly.
  468. setup_xfail *-*-*
  469. clear_xfail alpha-*-* bfin-*-linux* csky-*-* frv-*-* hppa*-*-* i?86-*-*
  470. clear_xfail ia64-*-* microblaze-*-* powerpc*-*-* x86_64-*-* xtensa-*-*
  471. run_ld_link_tests {
  472. {"pr22374 function pointer initialization"
  473. "" "tmpdir/pr22374.so" "" "pr22374a.s"
  474. { {readelf {--wide -r --dyn-syms} "pr22374-1.r"}
  475. {readelf {--wide -r} "pr22374-2.r"} }
  476. "pr22374" }
  477. }
  478. if { [istarget *-*-linux*]
  479. || [istarget *-*-nacl*]
  480. || [istarget *-*-gnu*] } {
  481. run_ld_link_tests {
  482. {"Weak symbols in dynamic objects 1 (support)"
  483. "-shared" "" "" {weak-dyn-1a.s}
  484. {}
  485. "libweakdyn1a.so"}
  486. {"Weak symbols in dynamic objects 1 (main test)"
  487. "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
  488. {{readelf {--relocs --wide} weak-dyn-1.rd}}
  489. "libweakdyn1b.so"}
  490. }
  491. }
  492. # Check to see if the C compiler works
  493. if { ![check_compiler_available] } {
  494. return
  495. }
  496. # Add -ldl to extralibs if needed
  497. set extralibs ""
  498. if { ![istarget *-*-freebsd*]} {
  499. set extralibs "-ldl"
  500. }
  501. set build_tests {
  502. {"Build libfoo.so"
  503. "-shared" "-fPIC"
  504. {foo.c} {} "libfoo.so"}
  505. {"Build versioned libfoo.so"
  506. "-shared -Wl,--version-script=foo.map" "-fPIC"
  507. {foo.c} {} "libfoov.so"}
  508. {"Build libbar.so"
  509. "-shared" "-fPIC"
  510. {begin.c end.c} {} "libbar.so"}
  511. {"Build warn libbar.so"
  512. "-shared" "-fPIC"
  513. {beginwarn.c end.c}
  514. {{readelf {-S --wide} libbarw.rd}
  515. {warning "^.*beginwarn.c:7: warning: function foo is deprecated\n?$"}}
  516. "libbarw.so" "c"}
  517. {"Build hidden libbar.so"
  518. "-shared" "-fPIC"
  519. {begin.c endhidden.c} {} "libbarh.so"}
  520. {"Build protected libbar.so"
  521. "-shared" "-fPIC"
  522. {begin.c endprotected.c} {} "libbarp.so"}
  523. {"Build libbar.so with libfoo.so"
  524. "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
  525. {end.c} {} "libbarfoo.so"}
  526. {"Build libar.so with versioned libfoo.so"
  527. "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
  528. {end.c} {} "libbarfoov.so"}
  529. {"Build hidden libbar.so with libfoo.so"
  530. "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
  531. {endhidden.c} {} "libbarhfoo.so"}
  532. {"Build hidden libar.so with versioned libfoo.so"
  533. "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
  534. {endhidden.c} {} "libbarhfoov.so"}
  535. {"Build protected libbar.so with libfoo.so"
  536. "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
  537. {endprotected.c} {} "libbarpfoo.so"}
  538. {"Build protected libbar.so with versioned libfoo.so"
  539. "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
  540. {endprotected.c} {} "libbarpfoov.so"}
  541. {"Build libdl1.so"
  542. "-shared" "-fPIC"
  543. {dl1.c} {} "libdl1.so"}
  544. {"Build libdl2a.so with --dynamic-list=dl2.list"
  545. "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
  546. {dl2.c dl2xxx.c} {} "libdl2a.so"}
  547. {"Build libdl2a.so with --dynamic-list=dl2a.list"
  548. "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
  549. {dl2.c dl2xxx.c} {} "libdl2a.so"}
  550. {"Build libdl2a.so with --dynamic-list-data"
  551. "-shared -Wl,--dynamic-list-data" "-fPIC"
  552. {dl2.c dl2xxx.c} {} "libdl2a.so"}
  553. {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
  554. "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
  555. {dl2.c dl2xxx.c} {} "libdl2b.so"}
  556. {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
  557. "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
  558. {dl2.c dl2xxx.c} {} "libdl2c.so"}
  559. {"Build libdl2d.so with --dynamic-list-data -Bsymbolic"
  560. "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
  561. {dl2.c dl2xxx.c} {} "libdl2d.so"}
  562. {"Build libdl2e.so with --export-dynamic-symbol=foo"
  563. "-shared -Wl,--export-dynamic-symbol=foo" "-fPIC"
  564. {dl2.c dl2xxx.c} {} "libdl2e.so"}
  565. {"Build libdl2f.so with --dynamic-list=dlempty.list and --export-dynamic-symbol=foo"
  566. "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol=foo" "-fPIC"
  567. {dl2.c dl2xxx.c} {} "libdl2f.so"}
  568. {"Build libdl2g.so with --export-dynamic-symbol-list=dl2.list"
  569. "-shared -Wl,--export-dynamic-symbol-list=dl2.list" "-fPIC"
  570. {dl2.c dl2xxx.c} {} "libdl2g.so"}
  571. {"Build libdl2h.so with --dynamic-list=dlempty.list and --export-dynamic-symbol-list=dl2.list"
  572. "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol-list=dl2.list" "-fPIC"
  573. {dl2.c dl2xxx.c} {} "libdl2h.so"}
  574. {"Build libdl2i.so with -Bsymbolic and --export-dynamic-symbol=foo"
  575. "-shared -Wl,-Bsymbolic,--export-dynamic-symbol=foo" "-fPIC"
  576. {dl2.c dl2xxx.c} {} "libdl2i.so"}
  577. {"Build libdl2j.so with -Bsymbolic and --export-dynamic-symbol-list=dl2.list"
  578. "-shared -Wl,-Bsymbolic,--export-dynamic-symbol-list=dl2.list" "-fPIC"
  579. {dl2.c dl2xxx.c} {} "libdl2j.so"}
  580. {"Build libdl2k.so with --export-dynamic-symbol-list=dl2.list and -Bsymbolic"
  581. "-shared -Wl,--export-dynamic-symbol-list=dl2.list,-Bsymbolic" "-fPIC"
  582. {dl2.c dl2xxx.c} {} "libdl2k.so"}
  583. # Check that -Bno-symbolic cancels -Bsymbolic.
  584. {"Build libdl2l.so with -Bsymbolic -Bno-symbolic and --export-dynamic-symbol=foo"
  585. "-shared -Wl,-Bsymbolic,-Bno-symbolic,--export-dynamic-symbol=foo" "-fPIC"
  586. {dl2.c dl2xxx.c} {} "libdl2l.so"}
  587. {"Build libdl4a.so with --dynamic-list=dl4.list"
  588. "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
  589. {dl4.c dl4xxx.c} {} "libdl4a.so"}
  590. {"Build libdl4b.so with --dynamic-list-data"
  591. "-shared -Wl,--dynamic-list-data" "-fPIC"
  592. {dl4.c dl4xxx.c} {} "libdl4b.so"}
  593. {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
  594. "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
  595. {dl4.c dl4xxx.c} {} "libdl4c.so"}
  596. {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
  597. "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
  598. {dl4.c dl4xxx.c} {} "libdl4d.so"}
  599. {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
  600. "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
  601. {dl4.c dl4xxx.c} {} "libdl4e.so"}
  602. {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
  603. "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
  604. {dl4.c dl4xxx.c} {} "libdl4f.so"}
  605. {"Build libdl6a.so"
  606. "-shared" "-fPIC"
  607. {dl6.c} {} "libdl6a.so"}
  608. {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
  609. "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
  610. {dl6.c} {} "libdl6b.so"}
  611. {"Build libdl6c.so with -Bsymbolic"
  612. "-shared -Wl,-Bsymbolic" "-fPIC"
  613. {dl6.c} {} "libdl6c.so"}
  614. {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
  615. "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
  616. {dl6.c} {} "libdl6d.so"}
  617. {"Build libdata1.so"
  618. "-shared" "-fPIC"
  619. {data1.c} {} "libdata1.so"}
  620. {"Build libdata2.so"
  621. "-shared" "-fPIC"
  622. {data2.c} {} "libdata2.so"}
  623. {"Build libcomm1.o"
  624. "-r -nostdlib" "-fcommon"
  625. {comm1.c} {} "libcomm1.o"}
  626. {"Build libfunc1.so"
  627. "-shared" "-fPIC"
  628. {func1.c} {} "libfunc1.so"}
  629. {"Build libpr9676-1.a"
  630. "" "-fPIC"
  631. {pr9676-1.c} {} "libpr9676-1.a"}
  632. {"Build libpr9676-2.a"
  633. "" "-fPIC"
  634. {pr9676-2.c} {} "libpr9676-2.a"}
  635. {"Build libpr9676-3.so"
  636. "-shared" "-fPIC"
  637. {pr9676-3.c} {} "libpr9676-3.so"}
  638. {"Build libpr9676-4.so"
  639. "-shared" "-fPIC"
  640. {pr9676-4.c} {} "libpr9676-4.so"}
  641. {"Build libpr9676-4a.so"
  642. "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
  643. "-fPIC"
  644. {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
  645. {"Build libpr9679.so"
  646. "-shared" "-fPIC -O0"
  647. {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
  648. {"Build libpr11138-1.so"
  649. "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
  650. {pr11138-1.c} {} "libpr11138-1.so"}
  651. {"Build libpr11138-2.o"
  652. "-r -nostdlib" ""
  653. {pr11138-2.c} {} "libpr11138-2.o"}
  654. {"Build pr13250-1.so"
  655. "-shared" "-fPIC -fcommon"
  656. {pr13250-1.c} {} "libpr13250-1.so"}
  657. {"Build pr13250-2.so with libpr13250-1.so"
  658. "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC -fcommon"
  659. {pr13250-2.c} {} "libpr13250-2.so"}
  660. {"Build libpr13250-3.o"
  661. "-r -nostdlib" "-fcommon"
  662. {pr13250-3.c} {} "libpr13250-3.o"}
  663. {"Build libpr14323-2.so"
  664. "-shared" "-fPIC -fcommon"
  665. {pr14323-2.c} {} "libpr14323-2.so"}
  666. {"Build pr14862-1.o"
  667. "-r -nostdlib" ""
  668. {pr14862-1.c} {} "libpr14862-1.o"}
  669. {"Build libpr14862.so"
  670. "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
  671. {pr14862-2.c} {} "libpr14862.so"}
  672. {"Build libneeded1b.so"
  673. "-shared" "-fPIC"
  674. {needed1b.c} {} "libneeded1b.so"}
  675. {"Build libneeded1a.so"
  676. "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
  677. {needed1a.c} {} "libneeded1a.so"}
  678. {"Build libneeded1c.o"
  679. "-r -nostdlib" ""
  680. {needed1c.c} {} "libneeded1c.o"}
  681. {"Build libneeded1pic.o"
  682. "-r -nostdlib" "-fPIC"
  683. {needed1c.c} {} "libneeded1pic.o"}
  684. {"Build needed1a.so with --add-needed"
  685. "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
  686. {dummy.c} {} "needed1a.so"}
  687. {"Build needed1b.so with --copy-dt-needed-entries"
  688. "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
  689. {dummy.c} {} "needed1b.so"}
  690. {"Build needed1a.so with --no-add-needed"
  691. "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
  692. {dummy.c} {} "needed1c.so"}
  693. {"Build needed1b.so with --no-copy-dt-needed-entries"
  694. "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
  695. {dummy.c} {} "needed1d.so"}
  696. {"Build librel.so"
  697. "-shared" "-fPIC"
  698. {rel.c} {} "librel.so"}
  699. {"Build libneeded2a.so"
  700. "-shared" "-fPIC"
  701. {needed2a.c} {} "libneeded2a.so"}
  702. {"Build libneeded2b.so"
  703. "-shared -Wl,--version-script,needed2.ver" "-fPIC"
  704. {needed2b.c} {} "libneeded2b.so"}
  705. {"Build libneeded2c.o"
  706. "-r -nostdlib" ""
  707. {needed2c.c} {} "libneeded2c.o"}
  708. {"Build needed2"
  709. "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
  710. {dummy.c} {} "needed2"}
  711. {"Build libneeded3a.so"
  712. "-shared -Wl,--no-add-needed" "-fPIC"
  713. {needed1a.c} {} "libneeded3a.so"}
  714. {"Build libneeded3b.so"
  715. "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
  716. {dummy.c} {} "libneeded3b.so"}
  717. {"Build needed3.o"
  718. "-r -nostdlib" ""
  719. {needed3.c} {} "libneeded3.so"}
  720. {"Build needed3"
  721. "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
  722. {dummy.c} {} "needed3"}
  723. {"Build rdynamic-1"
  724. "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
  725. {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
  726. {"Build dynamic-1"
  727. "-Wl,--no-dynamic-linker,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
  728. {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
  729. {"Build libpr16496a.so"
  730. "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
  731. {pr16496a.c} {} "libpr16496a.so"}
  732. {"Build libpr16496b.a"
  733. "" "-fPIC"
  734. {pr16496b.c} {} "libpr16496b.a"}
  735. {"Build libpr16496b.so"
  736. "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
  737. {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
  738. {"Build libpr16452a.so"
  739. "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
  740. {pr16452a.c} {} "libpr16452a.so"}
  741. {"Build libpr16452b.so"
  742. "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
  743. {dummy.c} {} "libpr16452b.so"}
  744. {"Build pr16452"
  745. "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
  746. {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
  747. {"Build pr16457"
  748. "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
  749. {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
  750. {"Build libpr18458a.so"
  751. "-shared -Wl,-z,now" "-fPIC"
  752. {pr18458a.c} {} "libpr18458a.so"}
  753. {"Build libpr18458b.so"
  754. "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
  755. {pr18458b.c} {} "libpr18458b.so"}
  756. }
  757. run_cc_link_tests [list \
  758. [list \
  759. "Build libpr2404a.so" \
  760. "-shared $NOSANITIZE_CFLAGS" \
  761. "-fPIC $NOSANITIZE_CFLAGS" \
  762. {pr2404a.c} \
  763. {} \
  764. "libpr2404a.so" \
  765. ] \
  766. [list \
  767. "Build libpr2404n.so" \
  768. "-shared -Wl,-z,now $NOSANITIZE_CFLAGS" \
  769. "-fPIC $NOSANITIZE_CFLAGS" \
  770. {pr2404a.c} \
  771. {} \
  772. "libpr2404n.so" \
  773. ] \
  774. [list \
  775. "Build libpr2404b.a" \
  776. "" \
  777. "$NOSANITIZE_CFLAGS" \
  778. {pr2404b.c} \
  779. {} \
  780. "libpr2404b.a" \
  781. ] \
  782. [list \
  783. "Build libpr26590a.so" \
  784. "-shared" \
  785. "-fPIC" \
  786. {pr26590a.c} \
  787. {} \
  788. "libpr26590a.so" \
  789. ] \
  790. [list \
  791. "Build libpr26590b.so (1)" \
  792. "-shared" \
  793. "-fPIC" \
  794. {pr26590b.c} \
  795. {} \
  796. "libpr26590b.so" \
  797. ] \
  798. [list \
  799. "Build pr26590c.o and pr26590d.o" \
  800. "" \
  801. "" \
  802. {pr26590c.c pr26590d.c} \
  803. {} \
  804. ] \
  805. [list \
  806. "Build pr26590 (1)" \
  807. "tmpdir/pr26590c.o tmpdir/pr26590d.o \
  808. -Wl,--as-needed tmpdir/libpr26590a.so tmpdir/libpr26590b.so" \
  809. "" \
  810. {dummy.c} \
  811. {{error_output pr26590.err}} \
  812. "pr26590" \
  813. ] \
  814. [list \
  815. "Build libpr26590b.so (2)" \
  816. "-shared -Wl,--no-as-needed \
  817. tmpdir/libpr26590a.so" \
  818. "-fPIC" \
  819. {pr26590b.c} \
  820. {} \
  821. "libpr26590b.so" \
  822. ] \
  823. [list \
  824. "Build pr26590 (2)" \
  825. "tmpdir/pr26590c.o tmpdir/pr26590d.o \
  826. -Wl,--as-needed tmpdir/libpr26590a.so tmpdir/libpr26590b.so" \
  827. "" \
  828. {dummy.c} \
  829. {} \
  830. "pr26590" \
  831. ] \
  832. [list \
  833. "Build libpr28348a.so" \
  834. "-shared -Wl,--version-script=pr28348.t" \
  835. "-fPIC" \
  836. {pr28348a.c} \
  837. {} \
  838. "libpr28348a.so" \
  839. ] \
  840. [list \
  841. "Build pr28348b.o" \
  842. "" \
  843. "-fPIC" \
  844. {pr28348b.c} \
  845. ] \
  846. [list \
  847. "Build pr28348c.o" \
  848. "" \
  849. "" \
  850. {pr28348c.c} \
  851. ] \
  852. [list \
  853. "Build libpr28348b.so" \
  854. "-shared -Wl,--version-script=pr28348.t \
  855. -Wl,--no-as-needed tmpdir/pr28348b.o tmpdir/libpr28348a.so" \
  856. "-fPIC" \
  857. {dummy.c} \
  858. {} \
  859. "libpr28348b.so" \
  860. ] \
  861. [list \
  862. "Build pr28348" \
  863. "-Wl,--no-as-needed tmpdir/pr28348c.o \
  864. tmpdir/pr28348a.o tmpdir/libpr28348a.so tmpdir/libpr28348b.so \
  865. tmpdir/libpr28348a.so" \
  866. "" \
  867. {dummy.c} \
  868. {{readelf {--dyn-syms --wide} pr28348.rd}} \
  869. "pr28348" \
  870. ] \
  871. ]
  872. # pr19073.s uses .set, which has a different meaning on alpha.
  873. if { ![istarget alpha-*-*] } {
  874. append build_tests {
  875. {"Build pr19073a.o"
  876. "-r -nostdlib" ""
  877. {pr19073.s} {} "pr19073a.o"}
  878. {"Build libpr19073.so"
  879. "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
  880. {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
  881. }
  882. }
  883. append build_tests {
  884. {"Build pr21964-1a.so"
  885. "-shared" "-fPIC"
  886. {pr21964-1a.c} {} "pr21964-1a.so"}
  887. {"Build pr21964-1b.so"
  888. "-shared" "-fPIC"
  889. {pr21964-1b.c} {} "pr21964-1b.so"}
  890. {"Build pr21964-2a.so"
  891. "-shared" "-fPIC"
  892. {pr21964-2a.c} {} "pr21964-2a.so"}
  893. {"Build pr21964-2b.so"
  894. "-shared" "-fPIC"
  895. {pr21964-2b.c} {} "pr21964-2b.so"}
  896. {"Build pr21964-3a.so"
  897. "-shared" "-fPIC"
  898. {pr21964-3a.c} {} "pr21964-3a.so"}
  899. {"Dump pr21978.so"
  900. "-shared" "-fPIC -g -O2"
  901. {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
  902. {"libpr26580-2.so"
  903. "-shared" "-fPIC -fcommon"
  904. {pr26580-b.c} {} "libpr26580-2.so"}
  905. }
  906. run_cc_link_tests $build_tests
  907. run_cc_link_tests [list \
  908. [list \
  909. "Build pr26094-1.so" \
  910. "-shared -Wl,--version-script=pr26094-1.ver" \
  911. "-fPIC" \
  912. {pr26094-1a.c} \
  913. {{readelf {--dyn-syms --wide} pr26094-1a.rd}} \
  914. "pr26094-1.so" \
  915. ] \
  916. [list \
  917. "Build pr26094-1" \
  918. "-Wl,--no-as-needed tmpdir/pr26094-1.so" \
  919. "-fcommon" \
  920. {pr26094-1b.c pr26094-1c.c} \
  921. {{readelf {--dyn-syms --wide} pr26094-1b.rd}} \
  922. "pr26094-1" \
  923. ] \
  924. [list \
  925. "Build pr26302a.so" \
  926. "-shared -Wl,--version-script=pr26302.ver" \
  927. "-fPIC" \
  928. {pr26302a.c} \
  929. {} \
  930. "pr26302a.so"
  931. ] \
  932. [list \
  933. "Build pr26302b.so" \
  934. "-shared -Wl,--no-as-needed tmpdir/pr26302a.so" \
  935. "-fPIC" \
  936. {pr26302b.c} \
  937. {{readelf {-sW} pr26302.rd} \
  938. {nm {-u} pr26302.nd} \
  939. {nm {-u -D} pr26302.nd} \
  940. {nm {-u -D --with-symbol-versions} pr26302.nd}} \
  941. "pr26302b.so" \
  942. ] \
  943. ]
  944. run_ld_link_tests [list \
  945. [list \
  946. "pr22269-1 (static pie undefined weak)" \
  947. "-pie -e _start --no-dynamic-linker -z text -z nocombreloc " \
  948. "" \
  949. "$AFLAGS_PIC" \
  950. { pr22269-1.c } \
  951. {{readelf -rW pr22269-1.rd}} \
  952. "pr22269-1" \
  953. "-fPIE -O2 $NOSANITIZE_CFLAGS" \
  954. ] \
  955. ]
  956. set run_tests [list \
  957. [list "Run normal with libfoo.so" \
  958. "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
  959. {main.c} "normal" "normal.out" ] \
  960. [list "Run protected with libfoo.so" \
  961. "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
  962. {main.c} "protected" "normal.out" ] \
  963. [list "Run hidden with libfoo.so" \
  964. "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
  965. {main.c} "hidden" "hidden.out" ] \
  966. [list "Run normal with versioned libfoo.so" \
  967. "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
  968. {main.c} "normalv" "normal.out" ] \
  969. [list "Run warn with versioned libfoo.so" \
  970. "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
  971. {main.c} "warn" "warn.out" \
  972. "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated\n?$} ] \
  973. [list "Run protected with versioned libfoo.so" \
  974. "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
  975. {main.c} "protected" "normal.out" ] \
  976. [list "Run hidden with versioned libfoo.so" \
  977. "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
  978. {main.c} "hiddenv" "hidden.out" ] \
  979. [list "Run normal libbar.so with libfoo.so" \
  980. "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
  981. {main.c} "normal" "normal.out" ] \
  982. [list "Run protected libbar.so with libfoo.so" \
  983. "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
  984. {main.c} "protected" "normal.out" ] \
  985. [list "Run hidden libbar.so with libfoo.so" \
  986. "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
  987. {main.c} "hidden" "hidden.out" ] \
  988. [list "Run normal libbar.so with versioned libfoo.so" \
  989. "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
  990. {main.c} "normal" "normal.out" ] \
  991. [list "Run protected libbar.so with versioned libfoo.so" \
  992. "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
  993. {main.c} "protected" "normal.out" ] \
  994. [list "Run hidden libbar.so with versioned libfoo.so" \
  995. "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
  996. {main.c} "hidden" "hidden.out" ] \
  997. [list "Run with libdl2a.so" \
  998. "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
  999. {dl2main.c} "dl2a" "dl2a.out" ] \
  1000. [list "Run with libdl2b.so" \
  1001. "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
  1002. {dl2main.c} "dl2b" "dl2b.out" ] \
  1003. [list "Run with libdl2c.so" \
  1004. "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
  1005. {dl2main.c} "dl2c" "dl2b.out" ] \
  1006. [list "Run with libdl2d.so" \
  1007. "-Wl,--no-as-needed tmpdir/libdl2d.so" "" \
  1008. {dl2main.c} "dl2d" "dl2a.out" ] \
  1009. [list "Run with libdl2e.so" \
  1010. "-Wl,--no-as-needed tmpdir/libdl2e.so" "" \
  1011. {dl2main.c} "dl2e" "dl2b.out" ] \
  1012. [list "Run with libdl2f.so" \
  1013. "-Wl,--no-as-needed tmpdir/libdl2f.so" "" \
  1014. {dl2main.c} "dl2f" "dl2a.out" ] \
  1015. [list "Run with libdl2g.so" \
  1016. "-Wl,--no-as-needed tmpdir/libdl2g.so" "" \
  1017. {dl2main.c} "dl2g" "dl2b.out" ] \
  1018. [list "Run with libdl2h.so" \
  1019. "-Wl,--no-as-needed tmpdir/libdl2h.so" "" \
  1020. {dl2main.c} "dl2h" "dl2a.out" ] \
  1021. [list "Run with libdl2i.so" \
  1022. "-Wl,--no-as-needed tmpdir/libdl2i.so" "" \
  1023. {dl2main.c} "dl2i" "dl2a.out" ] \
  1024. [list "Run with libdl2j.so" \
  1025. "-Wl,--no-as-needed tmpdir/libdl2j.so" "" \
  1026. {dl2main.c} "dl2j" "dl2a.out" ] \
  1027. [list "Run with libdl2k.so" \
  1028. "-Wl,--no-as-needed tmpdir/libdl2k.so" "" \
  1029. {dl2main.c} "dl2k" "dl2a.out" ] \
  1030. [list "Run with libdl2l.so" \
  1031. "-Wl,--no-as-needed tmpdir/libdl2l.so" "" \
  1032. {dl2main.c} "dl2l" "dl2b.out" ] \
  1033. [list "Run with libdl4a.so" \
  1034. "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
  1035. {dl4main.c} "dl4a" "dl4a.out" "-fPIC"] \
  1036. [list "Run with libdl4b.so" \
  1037. "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
  1038. {dl4main.c} "dl4b" "dl4a.out" "-fPIC"] \
  1039. [list "Run with libdl4c.so" \
  1040. "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
  1041. {dl4main.c} "dl4c" "dl4b.out" "-fPIC"] \
  1042. [list "Run with libdl4d.so" \
  1043. "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
  1044. {dl4main.c} "dl4d" "dl4b.out" "-fPIC"] \
  1045. [list "Run with libdl4e.so" \
  1046. "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
  1047. {dl4main.c} "dl4e" "dl4a.out" "-fPIC"] \
  1048. [list "Run with libdl4f.so" \
  1049. "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
  1050. {dl4main.c} "dl4f" "dl4a.out" "-fPIC"] \
  1051. [list "Run with libdata1.so" \
  1052. "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
  1053. {dynbss1.c} "dynbss1" "pass.out" ] \
  1054. [list "Run with libdata2.so" \
  1055. "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
  1056. {weakdef1.c} "weakdef1" "pass.out" ] \
  1057. [list "Run with libfunc1.so comm1.o" \
  1058. "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
  1059. {dummy.c} "comm1" "pass.out" ] \
  1060. [list "Run with comm1.o libfunc1.so" \
  1061. "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
  1062. {dummy.c} "comm1" "pass.out" ] \
  1063. [list "Run with pr11138-2.c libpr11138-1.so" \
  1064. "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
  1065. {dummy.c} "pr11138a" "pr11138.out" ] \
  1066. [list "Run with libpr11138-1.so pr11138-2.c" \
  1067. "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
  1068. {dummy.c} "pr11138b" "pr11138.out" ] \
  1069. [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
  1070. "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "-fcommon" \
  1071. {dummy.c} "pr13250" "pass.out" ] \
  1072. [list "Run with pr14323-1.c pr14323-2.so" \
  1073. "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
  1074. {pr14323-1.c} "pr14323" "pass.out" ] \
  1075. [list "Run with pr14862-1.c libpr14862.so" \
  1076. "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
  1077. {dummy.c} "pr14862" "pr14862.out" ] \
  1078. [list "Link with --add-needed" \
  1079. "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
  1080. {dummy.c} "needed1a" "needed1.out" ] \
  1081. [list "Link with --copy-dt-needed-entries" \
  1082. "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
  1083. {dummy.c} "needed1b" "needed1.out" ] \
  1084. [list "Run relmain" \
  1085. "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
  1086. {relmain.c} "relmain" "relmain.out" ] \
  1087. [list "Run pr2404" \
  1088. "$NOSANITIZE_CFLAGS -Wl,--no-as-needed \
  1089. tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
  1090. "" \
  1091. {dummy.c} "pr2404" "pr2404.out" \
  1092. "$NOSANITIZE_CFLAGS" ] \
  1093. [list "Run pr2404n" \
  1094. "$NOSANITIZE_CFLAGS -Wl,-z,now \
  1095. -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
  1096. {dummy.c} "pr2404n" "pr2404.out" \
  1097. "$NOSANITIZE_CFLAGS" ] \
  1098. [list "Run pr18458" \
  1099. "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
  1100. {pr18458c.c} "pr18458" "pass.out" ] \
  1101. [list "Run pr21964-1" \
  1102. "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \
  1103. {pr21964-1c.c} "pr21964-1" "pass.out" ] \
  1104. [list "Run pr21964-3" \
  1105. "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so tmpdir/pr21964-3a.so" "" \
  1106. {pr21964-3c.c} "pr21964-3" "pass.out" ] \
  1107. [list "pr26580-3" \
  1108. "" "" \
  1109. {pr26580-a.c} "pr26580-3" "pr26580-3.out" "-fcommon" "c" "" \
  1110. "-Wl,--as-needed tmpdir/libpr26580-2.so" ] \
  1111. [list "pr26580-4" \
  1112. "" "" \
  1113. {pr26580-a.c} "pr26580-4" "pr26580-4.out" "-fcommon" "c" "" \
  1114. "-Wl,--no-as-needed tmpdir/libpr26580-2.so" ] \
  1115. [list "Run pr26590 (2)" \
  1116. "" "" \
  1117. {pr26590c.c pr26590d.c} "pr26590" "pass.out" "" "c" "" \
  1118. "-Wl,--as-needed tmpdir/libpr26590a.so tmpdir/libpr26590b.so" ] \
  1119. ]
  1120. # NetBSD ELF systems do not currently support the .*_array sections.
  1121. run_ld_link_exec_tests $run_tests "*-*-netbsd*"
  1122. # These tests require dlopen support.
  1123. set dlopen_run_tests [list \
  1124. [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
  1125. "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
  1126. {dl1main.c} "dl1a" "dl1.out" ] \
  1127. [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
  1128. "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
  1129. {dl1main.c} "dl1b" "dl1.out" ] \
  1130. [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
  1131. "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
  1132. {dl6amain.c} "dl6a1" "dl6a.out" ] \
  1133. [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
  1134. "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
  1135. {dl6amain.c} "dl6a2" "dl6b.out" "$NOPIE_CFLAGS" ] \
  1136. [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
  1137. "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
  1138. {dl6amain.c} "dl6a3" "dl6b.out" ] \
  1139. [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
  1140. "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
  1141. {dl6amain.c} "dl6a4" "dl6a.out" ] \
  1142. [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
  1143. "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
  1144. {dl6amain.c} "dl6a5" "dl6b.out" "$NOPIE_CFLAGS" ] \
  1145. [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
  1146. "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
  1147. {dl6amain.c} "dl6a6" "dl6b.out" "$NOPIE_CFLAGS" ] \
  1148. [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
  1149. "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
  1150. {dl6amain.c} "dl6a7" "dl6a.out" "$NOPIE_CFLAGS" ] \
  1151. [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
  1152. "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
  1153. {dl6bmain.c} "dl6b1" "dl6a.out" ] \
  1154. [list "Run dl6b2 with dlopen on libdl6b.so" \
  1155. "-Wl,--no-as-needed $extralibs" "" \
  1156. {dl6bmain.c} "dl6b2" "dl6b.out" ] \
  1157. [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
  1158. "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
  1159. {dl6cmain.c} "dl6c1" "dl6b.out" ] \
  1160. [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
  1161. "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
  1162. {dl6dmain.c} "dl6d1" "dl6a.out" ] \
  1163. [list "Run pr21964-2" \
  1164. "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
  1165. {pr21964-2c.c} "pr21964-2" "pass.out" ] \
  1166. [list "Run pr21964-5" \
  1167. "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so $extralibs" "" \
  1168. {pr21964-5.c} "pr21964-5" "pass.out" ] \
  1169. ]
  1170. # Only run them when libdl is available.
  1171. if [check_libdl_available] {
  1172. # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
  1173. # sections.
  1174. # Disable all sanitizers.
  1175. set old_CFLAGS "$CFLAGS_FOR_TARGET"
  1176. append CFLAGS_FOR_TARGET " $NOSANITIZE_CFLAGS"
  1177. run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsd*"
  1178. set CFLAGS_FOR_TARGET "$old_CFLAGS"
  1179. }
  1180. # Check --no-add-needed and --no-copy-dt-needed-entries
  1181. set testname "--no-add-needed"
  1182. set exec_output [run_host_cmd "$CC_FOR_TARGET" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
  1183. if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
  1184. pass $testname
  1185. } {
  1186. fail $testname
  1187. }
  1188. set testname "--no-copy-dt-needed-entries"
  1189. set exec_output [run_host_cmd "$CC_FOR_TARGET" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
  1190. if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
  1191. pass $testname
  1192. } {
  1193. fail $testname
  1194. }
  1195. set testname "--no-add-needed -shared"
  1196. set exec_output [run_host_cmd "$CC_FOR_TARGET" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
  1197. if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
  1198. pass $testname
  1199. } {
  1200. fail $testname
  1201. }
  1202. set testname "--no-copy-dt-needed-entries -shared"
  1203. set exec_output [run_host_cmd "$CC_FOR_TARGET" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
  1204. if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
  1205. pass $testname
  1206. } {
  1207. fail $testname
  1208. }
  1209. # Check to see if the C++ compiler works
  1210. if { [which $CXX_FOR_TARGET] == 0 } {
  1211. return
  1212. }
  1213. set build_cxx_tests {
  1214. {"Build libdl3a.so with --dynamic-list=dl3.list"
  1215. "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
  1216. {dl3.cc} {} "libdl3a.so" "c++"}
  1217. {"Build libdl3b.so with -Bsymbolic"
  1218. "-shared -Wl,-Bsymbolic" "-fPIC"
  1219. {dl3.cc} {} "libdl3b.so" "c++"}
  1220. {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
  1221. "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
  1222. {dl3.cc} {} "libdl3c.so" "c++"}
  1223. }
  1224. run_cc_link_tests [list \
  1225. [list \
  1226. "Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new" \
  1227. "-shared $NOSANITIZE_CFLAGS -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" \
  1228. "-fPIC -ansi $NOSANITIZE_CFLAGS" \
  1229. {del.cc new.cc} \
  1230. {} \
  1231. "libnew1a.so" \
  1232. "c++" \
  1233. ] \
  1234. [list \
  1235. "Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new" \
  1236. "-shared $NOSANITIZE_CFLAGS -Wl,--dynamic-list-data,--dynamic-list-cpp-new" \
  1237. "-fPIC -ansi $NOSANITIZE_CFLAGS" \
  1238. {del.cc new.cc} \
  1239. {} \
  1240. "libnew1b.so" \
  1241. "c++" \
  1242. ] \
  1243. ]
  1244. # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
  1245. # {"Run with libdl3b.so"
  1246. # "tmpdir/libdl3b.so" ""
  1247. # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
  1248. set run_cxx_tests {
  1249. {"Run with libdl3a.so"
  1250. "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
  1251. {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
  1252. {"Run with libdl3c.so"
  1253. "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
  1254. {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
  1255. }
  1256. run_ld_link_exec_tests [list \
  1257. [list \
  1258. "Run with libnew1a.so" \
  1259. "-Wl,--no-as-needed tmpdir/libnew1a.so $NOSANITIZE_CFLAGS" \
  1260. "" \
  1261. {dl5.cc} \
  1262. "dl5a" \
  1263. "dl5.out" \
  1264. "-ansi $NOSANITIZE_CFLAGS" \
  1265. "c++" \
  1266. ] \
  1267. [list \
  1268. "Run with libnew1b.so" \
  1269. "-Wl,--no-as-needed tmpdir/libnew1b.so $NOSANITIZE_CFLAGS" \
  1270. "" \
  1271. {dl5.cc} \
  1272. "dl5b" \
  1273. "dl5.out" \
  1274. "-ansi $NOSANITIZE_CFLAGS" \
  1275. "c++" \
  1276. ] \
  1277. ]
  1278. run_cc_link_tests $build_cxx_tests
  1279. run_ld_link_exec_tests $run_cxx_tests
  1280. if { [istarget *-*-linux*]
  1281. || [istarget *-*-nacl*]
  1282. || [istarget *-*-gnu*] } {
  1283. run_cc_link_tests [list \
  1284. [list \
  1285. "Build libpr2404b.a with PIE" \
  1286. "" \
  1287. "-fPIE $NOSANITIZE_CFLAGS" \
  1288. { pr2404b.c } \
  1289. {} \
  1290. "libpr2404b.a" \
  1291. ] \
  1292. [list \
  1293. "Build pr19579a.o" \
  1294. "" "-fPIE -fcommon" \
  1295. {pr19579a.c} \
  1296. {} \
  1297. "libpr19579a.a" \
  1298. ] \
  1299. [list \
  1300. "Build libpr19579.so" \
  1301. "-shared" \
  1302. "-fPIC -fcommon" \
  1303. {pr19579b.c} \
  1304. {} \
  1305. "libpr19579.so" \
  1306. ] \
  1307. [list \
  1308. "Build libpr19579now.so" \
  1309. "-shared -Wl,-z,now" \
  1310. "-fPIC -fcommon" \
  1311. {pr19579b.c} \
  1312. {} \
  1313. "libpr19579.so" \
  1314. ] \
  1315. [list \
  1316. "Build pr22393-2a.so" \
  1317. "-shared -Wl,-z,separate-code" \
  1318. "-fPIC" \
  1319. {pr22393-2a.c} \
  1320. {{readelf -lW pr22393-2a.rd} \
  1321. {readelf -lW pr22393-2b.rd}} \
  1322. "pr22393-2a.so" \
  1323. ] \
  1324. [list \
  1325. "Build pr22393-2a-now.so" \
  1326. "-shared -Wl,-z,separate-code,-z,now" \
  1327. "-fPIC" \
  1328. {pr22393-2a.c} \
  1329. {{readelf -lW pr22393-2a.rd} \
  1330. {readelf -lW pr22393-2b.rd}} \
  1331. "pr22393-2a-now.so" \
  1332. ] \
  1333. [list \
  1334. "Build pr22393-2" \
  1335. "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
  1336. "$NOPIE_CFLAGS" \
  1337. {pr22393-2b.c} \
  1338. {{readelf -lW pr22393-2a.rd} \
  1339. {readelf -lW pr22393-2b.rd}} \
  1340. "pr22393-2" \
  1341. ] \
  1342. [list \
  1343. "Build pr22393-2 (PIE)" \
  1344. "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
  1345. "-fPIE" \
  1346. {pr22393-2b.c} \
  1347. {{readelf -lW pr22393-2a.rd} \
  1348. {readelf -lW pr22393-2b.rd}} \
  1349. "pr22393-2-pie" \
  1350. ] \
  1351. [list \
  1352. "Build pr22393-2 (static)" \
  1353. "-static -Wl,-z,separate-code" \
  1354. "" \
  1355. {pr22393-2a.c pr22393-2b.c} \
  1356. {{readelf -lW pr22393-2a.rd} \
  1357. {readelf -lW pr22393-2b.rd}} \
  1358. "pr22393-2-static" \
  1359. ] \
  1360. ]
  1361. run_ld_link_exec_tests [list \
  1362. [list \
  1363. "Run pr18458 with PIE" \
  1364. "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" \
  1365. "" \
  1366. {pr18458c.c} \
  1367. "pr18458p" \
  1368. "pass.out" \
  1369. "-fPIE" \
  1370. ] \
  1371. [list \
  1372. "Run pr2404 with PIE" \
  1373. "-pie $NOSANITIZE_CFLAGS -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
  1374. "" \
  1375. { dummy.c } \
  1376. "pr2404pie" \
  1377. "pr2404.out" \
  1378. "-fPIE $NOSANITIZE_CFLAGS" \
  1379. ] \
  1380. [list \
  1381. "Run pr2404 with PIE (-z now)" \
  1382. "-pie $NOSANITIZE_CFLAGS -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
  1383. "" \
  1384. { dummy.c } \
  1385. "pr2404pien" \
  1386. "pr2404.out" \
  1387. "-fPIE $NOSANITIZE_CFLAGS" \
  1388. ] \
  1389. [list \
  1390. "Run pr18718" \
  1391. "" \
  1392. "" \
  1393. { pr18718.c check-ptr-eq.c } \
  1394. "pr18718" \
  1395. "pass.out" \
  1396. "-O2 -I../bfd" \
  1397. ] \
  1398. [list \
  1399. "Run pr18718 (-z now)" \
  1400. "-Wl,-z,now" \
  1401. "" \
  1402. { pr18718.c check-ptr-eq.c } \
  1403. "pr18718" \
  1404. "pass.out" \
  1405. "-O2 -I../bfd" \
  1406. ] \
  1407. [list \
  1408. "Run pr18718 with PIE (1)" \
  1409. "-pie" \
  1410. "" \
  1411. { pr18718.c check-ptr-eq.c } \
  1412. "pr18718pie1" \
  1413. "pass.out" \
  1414. "-O2 -fPIE -I../bfd" \
  1415. ] \
  1416. [list \
  1417. "Run pr18718 with PIE (2)" \
  1418. "" \
  1419. "" \
  1420. { pr18718.c check-ptr-eq.c } \
  1421. "pr18718pie2" \
  1422. "pass.out" \
  1423. "-O2 -fPIE -I../bfd" \
  1424. ] \
  1425. [list \
  1426. "Run pr18718 with PIE (3)" \
  1427. "-pie -Wl,-z,now" \
  1428. "" \
  1429. { pr18718.c check-ptr-eq.c } \
  1430. "pr18718pie3" \
  1431. "pass.out" \
  1432. "-O2 -fPIE -I../bfd" \
  1433. ] \
  1434. [list \
  1435. "Run pr18718 with PIE (4)" \
  1436. "-Wl,-z,now" \
  1437. "" \
  1438. { pr18718.c check-ptr-eq.c } \
  1439. "pr18718pie4" \
  1440. "pass.out" \
  1441. "-O2 -fPIE -I../bfd" \
  1442. ] \
  1443. [list \
  1444. "Run pr18718 with PIC (1)" \
  1445. "" \
  1446. "" \
  1447. { pr18718.c check-ptr-eq.c } \
  1448. "pr18718pic1" \
  1449. "pass.out" \
  1450. "-O2 -fPIC -I../bfd" \
  1451. ] \
  1452. [list \
  1453. "Run pr18718 with PIC (2)" \
  1454. "-pie" \
  1455. "" \
  1456. { pr18718.c check-ptr-eq.c } \
  1457. "pr18718pic2" \
  1458. "pass.out" \
  1459. "-O2 -fPIC -I../bfd" \
  1460. ] \
  1461. [list \
  1462. "Run pr18718 with PIC (3)" \
  1463. "-Wl,-z,now" \
  1464. "" \
  1465. { pr18718.c check-ptr-eq.c } \
  1466. "pr18718pic3" \
  1467. "pass.out" \
  1468. "-O2 -fPIC -I../bfd" \
  1469. ] \
  1470. [list \
  1471. "Run pr18718 with PIC (4)" \
  1472. "-pie -Wl,-z,now" \
  1473. "" \
  1474. { pr18718.c check-ptr-eq.c } \
  1475. "pr18718pic4" \
  1476. "pass.out" \
  1477. "-O2 -fPIC -I../bfd" \
  1478. ] \
  1479. [list \
  1480. "Run pr19579" \
  1481. "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
  1482. "" \
  1483. {dummy.c} \
  1484. "pr19579" \
  1485. "pass.out" \
  1486. "-fPIE" \
  1487. ] \
  1488. [list \
  1489. "Run pr19579 (-z now)" \
  1490. "-pie -Wl,-z,now -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
  1491. "" \
  1492. {dummy.c} \
  1493. "pr19579n" \
  1494. "pass.out" \
  1495. "-fPIE" \
  1496. ] \
  1497. [list \
  1498. "Run pr22393-2" \
  1499. "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
  1500. "" \
  1501. {pr22393-2b.c} \
  1502. "pr22393-2" \
  1503. "pass.out" \
  1504. "$NOPIE_CFLAGS" \
  1505. ] \
  1506. [list \
  1507. "Run pr22393-2 (PIE)" \
  1508. "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
  1509. "" \
  1510. {pr22393-2b.c} \
  1511. "pr22393-2-pie" \
  1512. "pass.out" \
  1513. "-fPIE" \
  1514. ] \
  1515. [list \
  1516. "Run pr22393-2 (static)" \
  1517. "-static -Wl,-z,separate-code" \
  1518. "" \
  1519. {pr22393-2a.c pr22393-2b.c} \
  1520. "pr22393-2-static" \
  1521. "pass.out" \
  1522. ] \
  1523. [list \
  1524. "Run pr21964-4" \
  1525. "" \
  1526. "" \
  1527. {pr21964-4.c} \
  1528. "pr21964-4" \
  1529. "pass.out" \
  1530. "" \
  1531. "" \
  1532. "" \
  1533. "-ldl" \
  1534. ] \
  1535. ]
  1536. }
  1537. proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
  1538. run_cc_link_tests [list \
  1539. [list \
  1540. "Build libpr19719a.so" \
  1541. "-shared -Wl,-soname,libpr19719.so" \
  1542. "-fPIC" \
  1543. { pr19719d.c } \
  1544. {} \
  1545. "libpr19719a.so" \
  1546. ] \
  1547. [list \
  1548. "Build libpr19719b.so" \
  1549. "-shared -Wl,-soname,libpr19719.so" \
  1550. "-fPIC" \
  1551. { dummy.c } \
  1552. {} \
  1553. "libpr19719b.so" \
  1554. ] \
  1555. [list \
  1556. "Build libpr19719b.o" \
  1557. "-r -nostdlib" \
  1558. "-fPIC" \
  1559. { pr19719b.c } \
  1560. {} \
  1561. "libpr19719b.o" \
  1562. ] \
  1563. ]
  1564. send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
  1565. exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
  1566. run_ld_link_exec_tests [list \
  1567. [list \
  1568. "Run $exe fun defined" \
  1569. "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
  1570. "" \
  1571. { pr19719a.c pr19719c.c } \
  1572. $exe \
  1573. "pass.out" \
  1574. "$cflags" \
  1575. ] \
  1576. ]
  1577. send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
  1578. exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
  1579. foreach targ $xfails {
  1580. setup_xfail $targ
  1581. }
  1582. if ![isnative] {
  1583. unsupported "Run $exe fun undefined"
  1584. return
  1585. }
  1586. set exec_output [run_host_cmd "tmpdir/$exe" ""]
  1587. if {![string match "PASS" $exec_output]} {
  1588. fail "Run $exe fun undefined"
  1589. } else {
  1590. pass "Run $exe fun undefined"
  1591. }
  1592. }
  1593. mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
  1594. mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
  1595. set AFLAGS_PIE ""
  1596. if { [istarget "i?86-*-*"]
  1597. || [istarget "x86_64-*-*"] } {
  1598. set AFLAGS_PIE "-mrelax-relocations=yes"
  1599. }
  1600. if [istarget "sparc*-*-*"] {
  1601. set AFLAGS_PIE "-Av9"
  1602. }
  1603. if { ([istarget "*-*-linux*"]
  1604. || [istarget "*-*-nacl*"]
  1605. || [istarget "*-*-gnu*"])
  1606. && ![istarget "mips*-*-*"] } {
  1607. run_ld_link_tests [list \
  1608. [list \
  1609. "Build libpr23162a.so" \
  1610. "-shared" \
  1611. "" \
  1612. "$AFLAGS_PIC" \
  1613. { pr23162a.c } \
  1614. "" \
  1615. "libpr23162a.so" \
  1616. "-fPIC -O2 $NOSANITIZE_CFLAGS" \
  1617. ] \
  1618. [list \
  1619. "Build pr23162a" \
  1620. "-pie --no-as-needed tmpdir/libpr23162a.so" \
  1621. "" \
  1622. $AFLAGS_PIE \
  1623. { pr23162b.c } \
  1624. {{readelf {-rW} pr23162.rd}} \
  1625. "pr23162a" \
  1626. "-fPIC -O0 $NOSANITIZE_CFLAGS" \
  1627. ] \
  1628. [list \
  1629. "Build libpr23162b.so" \
  1630. "-shared --version-script=pr23162.map" \
  1631. "" \
  1632. "$AFLAGS_PIC" \
  1633. { pr23162a.c } \
  1634. "" \
  1635. "libpr23162b.so" \
  1636. "-fPIC -O2 $NOSANITIZE_CFLAGS" \
  1637. ] \
  1638. [list \
  1639. "Build pr23162b" \
  1640. "-pie --no-as-needed tmpdir/libpr23162b.so" \
  1641. "" \
  1642. $AFLAGS_PIE \
  1643. { pr23162b.c } \
  1644. {{readelf {-rW} pr23162.rd}} \
  1645. "pr23162b" \
  1646. "-fPIC -O0 $NOSANITIZE_CFLAGS" \
  1647. ] \
  1648. [list \
  1649. "Build libpr23161a.so" \
  1650. "-shared" \
  1651. "" \
  1652. "$AFLAGS_PIC" \
  1653. { pr23161a.c } \
  1654. {{readelf {--dyn-syms -rW} pr23161a.rd}} \
  1655. "libpr23161a.so" \
  1656. "-fPIC -O2 $NOSANITIZE_CFLAGS" \
  1657. ] \
  1658. [list \
  1659. "Build pr23161a" \
  1660. "-pie --no-as-needed tmpdir/libpr23161a.so" \
  1661. "" \
  1662. $AFLAGS_PIE \
  1663. { pr23161b.c } \
  1664. {{readelf {--dyn-syms -rW} pr23161b.rd}} \
  1665. "pr23161a" \
  1666. "-fPIC -O0 $NOSANITIZE_CFLAGS" \
  1667. ] \
  1668. [list \
  1669. "Build libpr23161b.so" \
  1670. "-shared --version-script=pr23161.map" \
  1671. "" \
  1672. "$AFLAGS_PIC" \
  1673. { pr23161a.c } \
  1674. {{readelf {--dyn-syms -rW} pr23161a.rd}} \
  1675. "libpr23161b.so" \
  1676. "-fPIC -O2 $NOSANITIZE_CFLAGS" \
  1677. ] \
  1678. [list \
  1679. "Build pr23161b" \
  1680. "-pie --no-as-needed tmpdir/libpr23161b.so" \
  1681. "" \
  1682. $AFLAGS_PIE \
  1683. { pr23161b.c } \
  1684. {{readelf {--dyn-syms -rW} pr23161b.rd}} \
  1685. "pr23161b" \
  1686. "-fPIC -O0 $NOSANITIZE_CFLAGS" \
  1687. ] \
  1688. ]
  1689. }
  1690. if { [istarget "i?86-*-*"]
  1691. || [istarget "x86_64-*-*"] } {
  1692. run_ld_link_tests [list \
  1693. [list \
  1694. "Build libpr23161c.so" \
  1695. "-shared" \
  1696. "" \
  1697. "$AFLAGS_PIC" \
  1698. { pr23161c.c } \
  1699. {{readelf {--dyn-syms -rW} pr23161c.rd}} \
  1700. "libpr23161c.so" \
  1701. "-fPIC -O2 $NOSANITIZE_CFLAGS" \
  1702. ] \
  1703. [list \
  1704. "Build pr23161c" \
  1705. "-pie --no-as-needed tmpdir/libpr23161c.so" \
  1706. "" \
  1707. $AFLAGS_PIE \
  1708. { pr23161b.c } \
  1709. {{readelf {--dyn-syms -rW} pr23161d.rd}} \
  1710. "pr23161c" \
  1711. "-fPIC -O0 $NOSANITIZE_CFLAGS" \
  1712. ] \
  1713. ]
  1714. }
  1715. run_ld_link_tests [list \
  1716. [list "Build pr23658.so" \
  1717. "-shared" "" "$AFLAGS_PIC" \
  1718. {pr23658-1a.s} {} "pr23658.so"] \
  1719. [list \
  1720. "Build pr23658-2" \
  1721. "--dynamic-linker tmpdir/pr23658.so --no-as-needed tmpdir/pr23658.so" \
  1722. "" \
  1723. $AFLAGS_NOTE \
  1724. { pr23658-1a.s pr23658-1b.s pr23658-1c.s pr23658-1d.s start.s } \
  1725. {{readelf {-lW} pr23658-2.rd}} \
  1726. "pr23658-2" \
  1727. ] \
  1728. ]