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