📄 objcopy.exp
字号:
set test "strip" if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { untested $test return } if [is_remote host] { set archive libstrip.a set objfile [remote_download host tmpdir/testprog.o] remote_file host delete $archive } else { set archive tmpdir/libstrip.a set objfile tmpdir/testprog.o } remote_file build delete tmpdir/libstrip.a set exec_output [binutils_run $AR "rc $archive ${objfile}"] if ![string match "" $exec_output] { fail $test return } set exec_output [binutils_run $STRIP "$STRIPFLAGS $archive"] if ![string match "" $exec_output] { fail $test return } if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { untested $test return } if [is_remote host] { set objfile [remote_download host tmpdir/testprog.o] } else { set objfile tmpdir/testprog.o } set exec_output [binutils_run $STRIP "$STRIPFLAGS $objfile"] if ![string match "" $exec_output] { fail $test return } set exec_output [binutils_run $NM "-a $NMFLAGS $objfile"] if ![string match "*: no symbols*" $exec_output] { fail $test return } pass $test}strip_test# Test stripping an object file with saving a symbolproc strip_test_with_saving_a_symbol { } { global CC global STRIP global STRIPFLAGS global NM global NMFLAGS global srcdir global subdir set test "strip with saving a symbol" if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } { untested $test return } if [is_remote host] { set objfile [remote_download host tmpdir/testprog.o] } else { set objfile tmpdir/testprog.o } set exec_output [binutils_run $STRIP "$STRIPFLAGS -K main -K _main $objfile"] if ![string match "" $exec_output] { fail $test return } set exec_output [binutils_run $NM "$NMFLAGS $objfile"] if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ && ![regexp {^([0-9a-fA-F]+)?[ ]+T _main} $exec_output]} { fail $test return } pass $test}strip_test_with_saving_a_symbol# Build a final executable.if { [istarget *-*-cygwin] || [istarget *-*-mingw32] } { set test_prog "testprog.exe"} else { set test_prog "testprog"}proc copy_setup { } { global srcdir global subdir global gcc_gas_flag global test_prog set res [build_wrapper testglue.o] set flags { debug } if { $res != "" } { lappend flags "additional_flags=[lindex $res 1]" set add_libs "testglue.o" } else { set add_libs "" } if { [istarget *-*-linux*] } { foreach i $gcc_gas_flag { set flags "additional_flags=$i $flags" } } if { [target_compile "$srcdir/$subdir/testprog.c $add_libs" tmpdir/$test_prog executable $flags] != "" } { return 2 } set result [remote_load target tmpdir/$test_prog] set status [lindex $result 0] if { $status != "pass" } { perror "unresolved setup, status = $status" return 3 } return 0}# Test copying an executable.proc copy_executable { prog flags test1 test2 } { global test_prog if [is_remote host] { set testfile [remote_download host tmpdir/$test_prog] set testcopy copyprog } else { set testfile tmpdir/$test_prog set testcopy tmpdir/copyprog } remote_file host delete $testcopy set exec_output [binutils_run $prog "$flags $testfile $testcopy"] if ![string match "" $exec_output] { fail $test1 fail $test2 return } if [is_remote host] { remote_upload host $testcopy tmpdir/copyprog } set status [remote_exec build "cmp" "tmpdir/$test_prog tmpdir/copyprog"] set exec_output [lindex $status 1] if [string match "" $exec_output] then { pass $test1 } else { send_log "$exec_output\n" verbose "$exec_output" # This will fail for many reasons. For example, it will most # likely fail if a non-GNU linker is used. Therefore, we do # not insist that it pass. If you are using an assembler and # linker based on the same BFD as objcopy, it is worth # investigating to see why this failure occurs. If we are # cross compiling, we assume that a GNU linker is being used, # and expect it to succeed. if {[isnative]} then { setup_xfail "*-*-*" } # This also fails for mips*-*-elf targets. See elf32-mips.c # mips_elf_sym_is_global. setup_xfail "mips*-*-elf" setup_xfail "*arm*-*-coff" setup_xfail "xscale-*-coff" setup_xfail "arm*-*-pe" setup_xfail "thumb*-*-coff" setup_xfail "thumb*-*-pe" fail $test1 } set output [remote_load target tmpdir/copyprog] set status [lindex $output 0] if { $status != "pass" } { fail $test2 } else { pass $test2 }}# Test stripping an executableproc strip_executable { prog flags test } { global NM global NMFLAGS remote_download build tmpdir/copyprog tmpdir/striprog if [is_remote host] { set copyfile [remote_download host tmpdir/striprog] } else { set copyfile tmpdir/striprog } set exec_output [binutils_run $prog "$flags ${copyfile}"] if ![string match "" $exec_output] { fail $test return } if [is_remote host] { remote_upload host ${copyfile} tmpdir/striprog } set result [remote_load target tmpdir/striprog] set status [lindex $result 0] if { $status != "pass" } { fail $test return } set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] if ![string match "*: no symbols*" $exec_output] { fail $test return } pass $test}# Test stripping an executable with saving a symbolproc strip_executable_with_saving_a_symbol { prog flags test } { global NM global NMFLAGS remote_download build tmpdir/copyprog tmpdir/striprog if [is_remote host] { set copyfile [remote_download host tmpdir/striprog] } else { set copyfile tmpdir/striprog } set exec_output [binutils_run $prog "$flags ${copyfile}"] if ![string match "" $exec_output] { fail $test return } if [is_remote host] { remote_upload host ${copyfile} tmpdir/striprog } set result [remote_load target tmpdir/striprog] set status [lindex $result 0] if { $status != "pass" } { fail $test return } set exec_output [binutils_run $NM "$NMFLAGS ${copyfile}"] if { [istarget mmix-knuth-mmixware] } { # Whenever there's a symbol in the mmo format, there's the symbol # Main, so remove it manually from the expected output for sake of # this test. # Using "" not {} to get the \n and \r translated. regsub "^\[0-9a-fA-F\]+\[ \]+T Main\[\n\r\]+" $exec_output "" exec_output } if {![regexp {^([0-9a-fA-F]+)?[ ]+[TD] main} $exec_output] \ && ![regexp {^([0-9a-fA-F]+)?[ ]+[TD] _main} $exec_output]} { fail $test return } pass $test}set test1 "simple objcopy of executable"set test2 "run objcopy of executable"set test3 "run stripped executable"set test4 "run stripped executable with saving a symbol"switch [copy_setup] { "1" { # do nothing } "2" { untested $test1 untested $test2 untested $test3 untested $test4 } "3" { unresolved $test1 unresolved $test2 unresolved $test3 unresolved $test4 } "0" { copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2" strip_executable "$STRIP" "$STRIPFLAGS" "$test3" strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4" }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -