| 1 |
# Builds various variants of an executable and a shared library |
| 2 |
# (with gcc/g++, -O0/-O3, prelinked/pie, seperate debuginfo) |
| 3 |
# Then runs tests with a list of execs. |
| 4 |
|
| 5 |
# Don't enable all sub-tests by default, enable them separately when |
| 6 |
# you want to track down an issue. |
| 7 |
# Enable just the all-in-one test for regular test runs to safe time |
| 8 |
#set subtestlist {lib mark uname ustack cleanup} |
| 9 |
set subtestlist {libmarkunamestack cleanup} |
| 10 |
|
| 11 |
proc seperate_debuginfo {elffile} { |
| 12 |
set objcopy [list "objcopy" "--only-keep-debug"] |
| 13 |
lappend objcopy "$elffile" |
| 14 |
lappend objcopy "${elffile}.debug" |
| 15 |
send_log "Executing: $objcopy\n" |
| 16 |
eval exec $objcopy |
| 17 |
|
| 18 |
set objcopy [list "objcopy" "--strip-debug"] |
| 19 |
lappend objcopy "$elffile" |
| 20 |
send_log "Executing: $objcopy\n" |
| 21 |
eval exec $objcopy |
| 22 |
|
| 23 |
set objcopy [list "objcopy"] |
| 24 |
lappend objcopy "--add-gnu-debuglink=${elffile}.debug" |
| 25 |
lappend objcopy "$elffile" |
| 26 |
send_log "Executing: $objcopy\n" |
| 27 |
eval exec $objcopy |
| 28 |
} |
| 29 |
|
| 30 |
set testnames {} |
| 31 |
|
| 32 |
set testpath "$srcdir/$subdir" |
| 33 |
set testsrc "$testpath/uprobes_exe.c" |
| 34 |
set testsrclib "$testpath/uprobes_lib.c" |
| 35 |
set testlibdir "." |
| 36 |
|
| 37 |
# When possible explicitly set 64 bit mode if kernel is 64 bit. |
| 38 |
switch -regexp $::tcl_platform(machine) { |
| 39 |
{^(x86_64|ppc64|s390x)$} { set arches [list "-m64"] } |
| 40 |
default { set arches [list "default"] } |
| 41 |
} |
| 42 |
|
| 43 |
# BUG! non-default arch breaks mark and ustack tests PR10318 and PR10272 |
| 44 |
#switch -regexp $::tcl_platform(machine) { |
| 45 |
# {^(x86_64|ppc64)$} { lappend arches "-m32" } |
| 46 |
# {^s390x$} { lappend arches "-m31" } |
| 47 |
#} |
| 48 |
switch -regexp $::tcl_platform(machine) { |
| 49 |
{x86_64} { lappend arches "-m32" } |
| 50 |
} |
| 51 |
|
| 52 |
foreach arch $arches { |
| 53 |
|
| 54 |
# Compiling with plain gcc. g++ is also supported but disabled |
| 55 |
# because it didn't add much interesting differences in binaries |
| 56 |
# and exploded the test search case a bit. |
| 57 |
foreach compiler {gcc} { # Add g++ |
| 58 |
|
| 59 |
# Just try -O3. |
| 60 |
# Adding -O0, -O, -O2, -Os and mixing lib/exe is a bit overdone |
| 61 |
foreach opt {-O3} { |
| 62 |
|
| 63 |
# Only use prelink if it exists on this platform |
| 64 |
if {[prelink_p]} { |
| 65 |
set libprelink_opts {no yes} |
| 66 |
} else { |
| 67 |
set libprelink_opts {no} |
| 68 |
} |
| 69 |
foreach libprelink $libprelink_opts { |
| 70 |
|
| 71 |
# not done yet, "no" lib debug. |
| 72 |
# seperate debuginfo can be done before or after prelinking |
| 73 |
# (after is only done if prelinking is also done |
| 74 |
foreach libdebug {yes sep sep-after} { |
| 75 |
|
| 76 |
set libname "uprobeslib${compiler}${opt}${arch}" |
| 77 |
|
| 78 |
if {$libprelink == "yes"} { |
| 79 |
set libname $libname-prelink |
| 80 |
} |
| 81 |
|
| 82 |
# This combination doesn't make sense |
| 83 |
if {$libdebug == "sep-after" && $libprelink == "no"} { |
| 84 |
continue; |
| 85 |
} |
| 86 |
|
| 87 |
if {$libdebug == "sep"} { |
| 88 |
set libname $libname-sep-debug |
| 89 |
} elseif {$libdebug == "sep-after"} { |
| 90 |
set libname $libname-sep-debug-after |
| 91 |
} else { |
| 92 |
set libname $libname-debug |
| 93 |
} |
| 94 |
|
| 95 |
# General compiler flags |
| 96 |
# We want the sdt.h from the source dir. |
| 97 |
set testflags [sdt_includes] |
| 98 |
# For now we always require debuginfo |
| 99 |
set testflags "$testflags additional_flags=-g" |
| 100 |
if {$arch != "default"} { |
| 101 |
set testflags "$testflags additional_flags=$arch" |
| 102 |
} |
| 103 |
if {$compiler == "g++"} { |
| 104 |
set testflags "$testflags additional_flags=-x additional_flags=c++" |
| 105 |
} |
| 106 |
set testflags "$testflags additional_flags=$opt" |
| 107 |
|
| 108 |
# Extra flags for libraries |
| 109 |
set testlibflags "$testflags additional_flags=-fPIC" |
| 110 |
set testlibflags "$testlibflags additional_flags=-shared" |
| 111 |
|
| 112 |
set testso "$testlibdir/lib${libname}.so" |
| 113 |
set res [target_compile $testsrclib $testso executable $testlibflags] |
| 114 |
if { $res != "" } { |
| 115 |
verbose "target_compile for $testso failed: $res" 2 |
| 116 |
fail "$libname compile [file tail $testsrclib]" |
| 117 |
return |
| 118 |
} else { |
| 119 |
pass "$libname compile [file tail $testsrclib]" |
| 120 |
} |
| 121 |
|
| 122 |
# seperate debuginfo before prelinking |
| 123 |
if {$libdebug == "sep"} { |
| 124 |
seperate_debuginfo $testso |
| 125 |
} |
| 126 |
|
| 127 |
if {$libprelink == "yes"} { |
| 128 |
if {![prelink $testso 0x6400000]} { |
| 129 |
fail "$libname prelink $testso" |
| 130 |
} else { |
| 131 |
pass "$libname prelink $testso" |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
# seperate debuginfo after prelinking |
| 136 |
if {$libdebug == "sep-after"} { |
| 137 |
seperate_debuginfo $testso |
| 138 |
} |
| 139 |
|
| 140 |
# should we also prelink exes? |
| 141 |
foreach exepie {no yes} { |
| 142 |
# not supported, "no" exe debug. |
| 143 |
foreach exedebug {yes sep} { |
| 144 |
|
| 145 |
set exename uprobes$compiler$opt$arch |
| 146 |
|
| 147 |
# Extra exe compile flags to include lib |
| 148 |
set testexeflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$libname additional_flags=-Wl,-rpath,$testlibdir" |
| 149 |
|
| 150 |
if {$exepie == "yes"} { |
| 151 |
set exename $exename-pie |
| 152 |
set testexeflags "$testexeflags additional_flags=-fPIE additional_flags=-pie" |
| 153 |
} |
| 154 |
|
| 155 |
if {$exedebug == "sep"} { |
| 156 |
set exename $exename-sep-debug |
| 157 |
} else { |
| 158 |
set exename $exename-debug |
| 159 |
} |
| 160 |
|
| 161 |
set exename $exename-$libname |
| 162 |
|
| 163 |
set testexe "$testlibdir/${exename}_exe" |
| 164 |
set res [target_compile $testsrc $testexe executable $testexeflags] |
| 165 |
if { $res != "" } { |
| 166 |
verbose "target_compile for $testexe failed: $res" 2 |
| 167 |
fail "$exename compile [file tail $testsrc]" |
| 168 |
return |
| 169 |
} else { |
| 170 |
pass "$exename compile [file tail $testsrc]" |
| 171 |
} |
| 172 |
|
| 173 |
if {$exedebug == "sep"} { |
| 174 |
seperate_debuginfo $testexe |
| 175 |
} |
| 176 |
|
| 177 |
set testname "${exename}_${libname}" |
| 178 |
lappend testnames $testname |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
# Call a test for each exe, set lib to shared library used |
| 188 |
foreach subtest $subtestlist { |
| 189 |
foreach testname $testnames { |
| 190 |
set exelib [split $testname {_}] |
| 191 |
set testexe [lindex $exelib 0] |
| 192 |
set testexe "${testlibdir}/${testexe}_exe" |
| 193 |
set testlib [lindex $exelib 1] |
| 194 |
set testlib "${testlibdir}/lib${testlib}.so" |
| 195 |
send_log "sourcing: $srcdir/$subdir/$subtest.tcl for $testname\n" |
| 196 |
source $srcdir/$subdir/$subtest.tcl |
| 197 |
} |
| 198 |
} |