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