This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Add an optional objcopy stage between gas and ld in run_dump_test
- From: Matthew Fortune <Matthew dot Fortune at imgtec dot com>
- To: "binutils at sourceware dot org" <binutils at sourceware dot org>
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Tue, 27 May 2014 14:04:50 +0000
- Subject: [PATCH] Add an optional objcopy stage between gas and ld in run_dump_test
- Authentication-results: sourceware.org; auth=none
As part of testing new MIPS ABI extensions I found a need to modify
objects between assembly and linking to trigger linker logic which
handles partly corrupted objects.
In my case I needed to remove a section and while strip can do this
too, objcopy will be more flexible for other uses in the future.
The feature adds a new keyword: objcopy_objects which takes the
flags for objcopy. It also adds a pseudo-option for source specific
assembly flags called RUN_OBJCOPY. Any source with this pseudo-option
will have its corresponding object run through objcopy with the
specified flags and then go on to link as usual.
An example usage:
#source: jr.s -march=octeon -32 -mfp64 -EB RUN_OBJCOPY
#source: jr.s -mips32r2 -32 -mfpxx -EB
#ld: -melf32btsmip -e 0
#objcopy_objects: -R .MIPS.abiflags
#objdump: -p
This will remove .MIPS.abiflags from the first object but not the
second and then link.
Comments/OK to commit?
Regards,
Matthew
ld/testsuite/
* lib/ld-lib.exp: Add objcopy_objects command to run_dump_test.
This allows each input object to be optionally run through
objcopy before linking.
---
ld/testsuite/lib/ld-lib.exp | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/ld/testsuite/lib/ld-lib.exp b/ld/testsuite/lib/ld-lib.exp
index 369dc1f..c3af59c 100644
--- a/ld/testsuite/lib/ld-lib.exp
+++ b/ld/testsuite/lib/ld-lib.exp
@@ -497,6 +497,11 @@ proc ld_simple_link_defsyms {} {
# ld_after_inputfiles: FLAGS
# Similar to "ld", but put after all input files.
#
+# objcopy_objects: FLAGS
+# Run objcopy with the specified flags after assembling any source
+# that has the special marker RUN_OBJCOPY in the source specific
+# flags.
+#
# objcopy_linked_file: FLAGS
# Run objcopy on the linked file with the specified flags.
# This lets you transform the linked file using objcopy, before the
@@ -605,6 +610,7 @@ proc run_dump_test { name {extra_options {}} } {
set opts(error) {}
set opts(warning) {}
set opts(objcopy_linked_file) {}
+ set opts(objcopy_objects) {}
foreach i $opt_array {
set opt_name [lindex $i 0]
@@ -784,6 +790,12 @@ proc run_dump_test { name {extra_options {}} } {
for { set i 0 } { $i < [llength $sourcefiles] } { incr i } {
set sourcefile [lindex $sourcefiles $i]
set sourceasflags [lindex $asflags $i]
+ set run_objcopy_objects 0
+
+ if { [string match "*RUN_OBJCOPY*" $sourceasflags] } {
+ set run_objcopy_objects 1
+ }
+ regsub "RUN_OBJCOPY" $sourceasflags "" sourceasflags
set objfile "tmpdir/dump$i.o"
catch "exec rm -f $objfile" exec_output
@@ -807,6 +819,30 @@ proc run_dump_test { name {extra_options {}} } {
fail $testname
return
}
+
+ if { $run_objcopy_objects } {
+ set cmd "$OBJCOPY $opts(objcopy_objects) $objfile"
+
+ send_log "$cmd\n"
+ set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] \
+ "" "/dev/null" "objcopy.tmp"]
+ remote_upload host "objcopy.tmp"
+ set comp_output [prune_warnings [file_contents "objcopy.tmp"]]
+ remote_file host delete "objcopy.tmp"
+ remote_file build delete "objcopy.tmp"
+
+ if { [lindex $cmdret 0] != 0 \
+ || ![string match "" $comp_output] } {
+ send_log "$comp_output\n"
+ verbose "$comp_output" 3
+
+ set exitstat "succeeded"
+ if { $cmdret != 0 } { set exitstat "failed" }
+ verbose -log "$exitstat with: <$comp_output>"
+ fail $testname
+ return
+ }
+ }
}
set expmsg $opts(error)
--
1.7.1