Home | History | Annotate | Line # | Download | only in libctf-regression
      1  1.1.1.4  christos # Copyright (C) 2021-2025 Free Software Foundation, Inc.
      2      1.1  christos #
      3      1.1  christos # This file is part of the GNU Binutils.
      4      1.1  christos #
      5      1.1  christos # This program is free software; you can redistribute it and/or modify
      6      1.1  christos # it under the terms of the GNU General Public License as published by
      7      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      8      1.1  christos # (at your option) any later version.
      9      1.1  christos #
     10      1.1  christos # This program is distributed in the hope that it will be useful,
     11      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13      1.1  christos # GNU General Public License for more details.
     14      1.1  christos #
     15      1.1  christos # You should have received a copy of the GNU General Public License
     16      1.1  christos # along with this program; if not, write to the Free Software
     17      1.1  christos # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     18      1.1  christos # MA 02110-1301, USA.
     19      1.1  christos #
     20      1.1  christos 
     21      1.1  christos load_file $srcdir/../../ld/testsuite/lib/ld-lib.exp
     22      1.1  christos 
     23      1.1  christos global srcdir subdir OBJDUMP
     24      1.1  christos global testname
     25      1.1  christos global subsrcdir
     26      1.1  christos 
     27      1.1  christos set subsrcdir "$srcdir/$subdir/"
     28  1.1.1.3  christos set testname "libctf-repeat-cu.exp"
     29      1.1  christos 
     30      1.1  christos if ![is_elf_format] {
     31      1.1  christos     unsupported "CTF needs bfd changes to be emitted on non-ELF"
     32      1.1  christos     return 0
     33      1.1  christos }
     34      1.1  christos 
     35      1.1  christos if {![check_ctf_available]} {
     36      1.1  christos     unsupported "no CTF format support in the compiler"
     37      1.1  christos     return 0
     38      1.1  christos }
     39      1.1  christos 
     40  1.1.1.4  christos if {![check_ctf_linker_dedup]} {
     41  1.1.1.4  christos     unsupported "no CTF deduplication support in the linker"
     42  1.1.1.4  christos     return 0
     43  1.1.1.4  christos }
     44  1.1.1.4  christos 
     45      1.1  christos if {[info exists env(LC_ALL)]} {
     46      1.1  christos     set old_lc_all $env(LC_ALL)
     47      1.1  christos }
     48      1.1  christos set env(LC_ALL) "C"
     49      1.1  christos 
     50      1.1  christos # Compile one SRC to OBJ and put it into ARCHIVE.
     51      1.1  christos proc one_lib_compile { src flags obj archive } {
     52      1.1  christos     global CC_FOR_TARGET CFLAGS_FOR_TARGET AR subsrcdir
     53      1.1  christos 
     54      1.1  christos     if [is_remote host] {
     55      1.1  christos 	set src [remote_download host [file join $subsrcdir $src]]
     56      1.1  christos     } else {
     57      1.1  christos 	set src [file join $subsrcdir $src]
     58      1.1  christos     }
     59      1.1  christos 
     60      1.1  christos     set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET $flags -gctf -fPIC -c -o $obj $src"]]
     61      1.1  christos     if { $comp_output != "" } {
     62      1.1  christos 	return $comp_output
     63      1.1  christos     }
     64      1.1  christos 
     65      1.1  christos     set ar_output [prune_warnings [run_host_cmd "$AR" "rc $archive $obj"]]
     66      1.1  christos     return $comp_output
     67      1.1  christos }
     68      1.1  christos 
     69      1.1  christos # Compile one SRC to OBJ and put it into ARCHIVE: error-check the result.
     70      1.1  christos proc one_lib_compile_check { src flags obj archive } {
     71      1.1  christos     global testname
     72      1.1  christos 
     73      1.1  christos     set comp_output [one_lib_compile $src $flags $obj $archive]
     74      1.1  christos 
     75      1.1  christos     if { $comp_output != ""} {
     76      1.1  christos 	send_log "compilation of $src with $flags failed with <$comp_output>"
     77      1.1  christos 	perror "compilation of $src with $flags failed"
     78      1.1  christos 	fail $testname
     79      1.1  christos 	return 0
     80      1.1  christos     }
     81      1.1  christos     return 1
     82      1.1  christos }
     83      1.1  christos 
     84      1.1  christos if { ! [one_lib_compile_check libctf-repeat-cu-lib.c "-DINT -DFUN=a" tmpdir/libctf-repeat-cu-lib.o tmpdir/a.a] } {
     85      1.1  christos     return 0
     86      1.1  christos }
     87      1.1  christos 
     88      1.1  christos if { ! [one_lib_compile_check libctf-repeat-cu-lib.c "-DCHAR -DFUN=b" tmpdir/libctf-repeat-cu-lib.o tmpdir/b.a] } {
     89      1.1  christos     return 0
     90      1.1  christos }
     91      1.1  christos 
     92      1.1  christos if { ! [one_lib_compile_check libctf-repeat-cu-lib.c "-DFUN=c" tmpdir/libctf-repeat-cu-lib.o tmpdir/c.a] } {
     93      1.1  christos     return 0
     94      1.1  christos }
     95      1.1  christos 
     96      1.1  christos if [is_remote host] {
     97      1.1  christos     set src [remote_download host [file join $subsrcdir libctf-repeat-cu-main.c]]
     98      1.1  christos } else {
     99      1.1  christos     set src [file join $subsrcdir libctf-repeat-cu-main.c]
    100      1.1  christos }
    101      1.1  christos 
    102      1.1  christos set comp_output [prune_warnings [run_host_cmd "$CC_FOR_TARGET" "$CFLAGS_FOR_TARGET -gctf -fPIC -shared -o tmpdir/libctf-repeat-cu-main.so $src tmpdir/a.a tmpdir/b.a tmpdir/c.a"]]
    103      1.1  christos if { $comp_output != "" } {
    104      1.1  christos     send_log "compilation of tmpdir/libctf-repeat-cu-main.so failed"
    105      1.1  christos     perror "compilation of tmpdir/libctf-repeat-cu-main.so failed"
    106      1.1  christos     fail $testname
    107      1.1  christos     return $comp_output
    108      1.1  christos }
    109      1.1  christos 
    110      1.1  christos set comp_output [prune_warnings [run_host_cmd "$OBJDUMP" "--ctf tmpdir/libctf-repeat-cu-main.so > tmpdir/dump.out"]]
    111      1.1  christos 
    112      1.1  christos if { [regexp_diff "tmpdir/dump.out"  [file join $subsrcdir libctf-repeat-cu.d] ] } {
    113      1.1  christos     fail $testname
    114      1.1  christos     if { $verbose == 2 } then { verbose "output is [file_contents tmpdir/dump.out]" 2 }
    115      1.1  christos }
    116      1.1  christos 
    117      1.1  christos pass $testname
    118      1.1  christos 
    119      1.1  christos if {[info exists old_lc_all]} {
    120      1.1  christos     set env(LC_ALL) $old_lc_all
    121      1.1  christos } else {
    122      1.1  christos     unset env(LC_ALL)
    123      1.1  christos }
    124