1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
# Do any platform-specific initialize for the 'arch_compile' library.
proc arch_compile_init {} {
global systemtap_arch_compile_flags
# RHEL[67] ppc64 systems can build both 64-bit and 32-bit
# executables. Fedora 24 ppc64 has dropped 32-bit exe support. So,
# if we're on ppc64 and the 32-bit exe compilation fails here, we
# assume that 32-bit exe support is unavailable.
#
# Note that it is possible that 32-bit exe support is available just
# not installed (on RHEL[67] anyway), but we can't really tell the
# difference.
# Various other RHEL products now started deprecating the compat arch
# support, such as devtoolset (non-x86_64 arches), rhel-alt etc.
# Instead of hardcoding the systemtap_arch_compile_flags values, we
# always check for available support.
#
# Drawback is that when the compat arch support is available but not
# installed, the testsuite will silently skip examining it. OTOH,
# this new behaviour gives more flexibility, and aligns to how some
# other dejagnu testsuites (e.g. strace) behave.
set platform_machine $::tcl_platform(machine)
set compat_arch_bits 32
if { [regexp "^(s390x)$" $::tcl_platform(machine)] } {
set compat_arch_bits 31
}
# Create a tempory directory.
if {[catch {exec mktemp -d -t staptestXXXXXX-arch_compile-test} tmpdir]} {
verbose -log "Failed to create temporary directory: $tmpdir"
exit 1
}
set curdir [pwd]
cd ${tmpdir}
set source "hello.c"
set hello_file [open $source "w"]
puts $hello_file "#include <stdio.h>"
puts $hello_file "int main () { printf(\"Hello World!\"); return 0; }"
close $hello_file
set systemtap_arch_compile_flags 0
puts "Checking for 64-bit support..."
set flags "compiler=gcc additional_flags=-g"
# GCC on aarch64 doesn't recognize -m64; But it's the default
if { ![regexp "^(aarch64)$" $::tcl_platform(machine)] } {
set flags "$flags additional_flags=-m64"
}
set exe "hello-m64"
set result [target_compile $source $exe executable $flags]
if { $result != "" } {
puts "$platform_machine 64-bit support unavailable"
} else {
puts "$platform_machine 64-bit support available"
incr systemtap_arch_compile_flags
}
puts "Checking for $compat_arch_bits-bit support..."
set flags "additional_flags=-g compiler=gcc additional_flags=-m$compat_arch_bits"
set exe "hello-m$compat_arch_bits"
set result [target_compile $source $exe executable $flags]
if { $result != "" } {
puts "$platform_machine $compat_arch_bits-bit support unavailable"
} else {
puts "$platform_machine $compat_arch_bits-bit support available"
incr systemtap_arch_compile_flags
}
cd ${curdir}
catch {exec rm -rf $tmpdir}
}
# Number of different compile flags for this arch.
proc arch_compile_flags {} {
global systemtap_arch_compile_flags
return $systemtap_arch_compile_flags
}
# Additional compile flag to use for with target_compile.
# Given INDEX starts at zero and should be smaller than the number
# returned by arch_compile_flags.
proc arch_compile_flag { INDEX } {
if { [arch_compile_flags] == 1 } {
return ""
}
switch $INDEX {
0 {
return "additional_flags=-m64"
}
1 {
switch -regexp $::tcl_platform(machine) {
{^s390x$} { return "additional_flags=-m31" }
default { return "additional_flags=-m32" }
}
}
}
}
# Name of compile flag to use in generated files or user/test messages.
# Given INDEX starts at zero and should be smaller than the number
# returned by arch_compile_flags.
proc arch_compile_flag_name { INDEX } {
if { [arch_compile_flags] == 1 } {
switch -regexp $::tcl_platform(machine) {
{^(ia64|aarch64|ppc64le|ppc64)$} { return "m64" }
{^s390$} { return "m31" }
{^mips64$} { return "64" }
default { return "m32" }
}
}
switch $INDEX {
0 {
return "m64"
}
1 {
switch -regexp $::tcl_platform(machine) {
{^s390x$} { return "m31" }
default { return "m32" }
}
}
}
}
# Number of bits for compile flag for use in generated files or
# user/test messages.
#
# Given INDEX starts at zero and should be smaller than the number
# returned by arch_compile_flags.
proc arch_compile_flag_bits { INDEX } {
# Notice that even though s390/s390x is 31 bits, we'll call it 32.
if { [arch_compile_flags] == 1 } {
switch -regexp $::tcl_platform(machine) {
{^(ia64|aarch64|ppc64le|ppc64|mips64|s390x)$} { return 64 }
default { return 32 }
}
}
switch $INDEX {
0 { return 64 }
1 { return 32 }
}
}
# Number of different combinations of compile flags.
proc all_compile_flags {} {
# There are 3 sets of flags for each architecture.
return [expr 3 * [arch_compile_flags]]
}
# Is INDEX a native (i.e. non-multiarch) configuration?
proc all_compile_flag_native_p { INDEX } {
set arch_index [expr $INDEX % [arch_compile_flags]]
if { $arch_index == 0 } {
return 1
}
return 0
}
# Is INDEX a configuration with optimization turned on?
proc all_compile_flag_optimized_p { INDEX } {
return [expr (($INDEX / 2) % 3) > 0]
}
# Additional compile flag to use for with target_compile.
# Given INDEX starts at zero and should be smaller than the number
# returned by all_compile_flags.
proc all_compile_flag { INDEX } {
set opt_flags [list "" "additional_flags=-O" "additional_flags=-O2" ]
set arch_index [expr $INDEX % [arch_compile_flags]]
set opt_flag [lindex $opt_flags [expr ($INDEX / 2) % 3]]
return "[arch_compile_flag $arch_index] $opt_flag"
}
# Name of compile flag to use in generated files or user/test messages.
# Given INDEX starts at zero and should be smaller than the number
# returned by arch_compile_flags.
proc all_compile_flag_name { INDEX } {
set opt_names [list "" "-O" "-O2" ]
set arch_index [expr $INDEX % [arch_compile_flags]]
set opt_name [lindex $opt_names [expr ($INDEX / 2) % 3]]
return "[arch_compile_flag_name $arch_index]$opt_name"
}
|