Skip to content

Commit

Permalink
util: use gaol for tool chain
Browse files Browse the repository at this point in the history
This is in preparation of moving the tool chain into a squashfs image.

genodelabs#99
  • Loading branch information
jschlatow committed Oct 1, 2024
1 parent fa6a92d commit e7e28b4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 67 deletions.
77 changes: 77 additions & 0 deletions share/goa/lib/actions/build.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,38 @@ namespace eval goa {
}


proc gaol_with_toolchain { {silent 0} } {

global gaol verbose allowed_tools

set cmd $gaol
lappend cmd --system-usr

foreach dir [lsearch -all -inline -not $allowed_tools /usr*] {
lappend cmd --ro-bind $dir }

if {$verbose && !$silent} {
lappend cmd --verbose }

return $cmd
}


proc exec_tool_chain { bin args } {

global config::cross_dev_prefix config::build_dir

set cmd [gaol_with_toolchain 1]

if {[file exists $build_dir]} {
lappend cmd --bind $build_dir }

lappend cmd $cross_dev_prefix$bin

exec {*}$cmd {*}$args
}


proc used_apis { } {

variable _used_apis
Expand All @@ -66,6 +98,51 @@ namespace eval goa {
return $_used_apis
}

##
# strip debug symbols from binary
#
proc strip_binary { file } {
catch { exec_tool_chain strip "$file" }
}


##
# extract debug info files
#
proc extract_debug_info { file } {

##
# check whether file has debug info and bail if not
#

if {[catch { exec_tool_chain objdump -hj .debug_info "$file" }]} {
diag "file \"$file\" has no debug info"
return }

##
# create debug info file
#
#
if {[catch { exec_tool_chain objcopy --only-keep-debug "$file" "$file.debug" }]} {
diag "unable to extract debug info file from $file"
return
}

##
# add gnu_debuglink section to binary
#

# change dir because --add-gnu-debuglink expect .debug file in working dir
set filename [file tail $file]
set orig_pwd [pwd]
cd [file dirname $file]

if {[catch { exec_tool_chain objcopy --add-gnu-debuglink=$filename.debug $filename }]} {
diag "unable to add gnu_debuglink section to $file" }

cd $orig_pwd
}


##
# Return 1 if specified API is used
Expand Down
2 changes: 1 addition & 1 deletion share/goa/lib/flags.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ foreach api [used_apis] {
lappend include_dirs $dir
}

set libgcc_path [unsafe_file normalize [eval "exec $cross_dev_prefix\gcc -print-libgcc-file-name"]]
set libgcc_path [unsafe_file normalize [eval "exec_tool_chain gcc -print-libgcc-file-name"]]
set libgcc_include [file join [file dirname $libgcc_path] include]

lappend include_dirs [unsafe_file normalize $libgcc_include]
Expand Down
66 changes: 0 additions & 66 deletions share/goa/lib/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -906,69 +906,3 @@ proc assert_definition_of_depot_user { } {
"\n variable in a goarc file, or by specifing the '--depot-user <name>'"\
"\n command-line argument.\n"
}


##
# strip debug symbols from binary
#
proc strip_binary { file } {
global config::cross_dev_prefix

set cmd "$cross_dev_prefix\strip"
lappend cmd "$file"

catch { exec {*}$cmd }
}


##
# extract debug info files
#
proc extract_debug_info { file } {
global config::cross_dev_prefix config::dbg_dir

##
# check whether file has debug info and bail if not
#

set cmd "$cross_dev_prefix\objdump"
lappend cmd "-hj"
lappend cmd ".debug_info"
lappend cmd "$file"

if {[catch { exec {*}$cmd }]} {
diag "file \"$file\" has no debug info"
return }

##
# create debug info file
#

set cmd "$cross_dev_prefix\objcopy"
lappend cmd "--only-keep-debug"
lappend cmd "$file"
lappend cmd "$file.debug"

if {[catch { exec {*}$cmd }]} {
diag "unable to extract debug info file from $file"
return
}

##
# add gnu_debuglink section to binary
#

# change dir because --add-gnu-debuglink expect .debug file in working dir
set filename [file tail $file]
set orig_pwd [pwd]
cd [file dirname $file]

set cmd "$cross_dev_prefix\objcopy"
lappend cmd "--add-gnu-debuglink=$filename.debug"
lappend cmd "$filename"

if {[catch { exec {*}$cmd }]} {
diag "unable to add gnu_debuglink section to $file" }

cd $orig_pwd
}

0 comments on commit e7e28b4

Please sign in to comment.