public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gas: Add CodeView constant for aarch64
@ 2023-01-26  0:38 Mark Harmstone
  2023-01-26  0:38 ` [PATCH 2/2] gas/testsuite: Add -gcodeview test for aarch64-w64-mingw32 Mark Harmstone
  2023-01-26  9:26 ` [PATCH 1/2] gas: Add CodeView constant for aarch64 Jan Beulich
  0 siblings, 2 replies; 6+ messages in thread
From: Mark Harmstone @ 2023-01-26  0:38 UTC (permalink / raw)
  To: binutils; +Cc: Mark Harmstone

Adds the correct constant to the S_COMPILE3 CodeView record when
assembling aarch64-w64-mingw32 with the -gcodeview flag.

---
 gas/codeview.c | 19 +++++++++++++------
 gas/codeview.h |  1 +
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/gas/codeview.c b/gas/codeview.c
index 2d96d4467fc..0d5f82848a5 100644
--- a/gas/codeview.c
+++ b/gas/codeview.c
@@ -286,13 +286,20 @@ write_lines_info (void)
 static uint16_t
 target_processor (void)
 {
-  if (stdoutput->arch_info->arch != bfd_arch_i386)
-    return 0;
+  switch (stdoutput->arch_info->arch)
+    {
+    case bfd_arch_i386:
+      if (stdoutput->arch_info->mach & bfd_mach_x86_64)
+	return CV_CFL_X64;
+      else
+	return CV_CFL_80386;
 
-  if (stdoutput->arch_info->mach & bfd_mach_x86_64)
-    return CV_CFL_X64;
-  else
-    return CV_CFL_80386;
+    case bfd_arch_aarch64:
+      return CV_CFL_ARM64;
+
+    default:
+      return 0;
+    }
 }
 
 /* Write the CodeView symbols, describing the object name and
diff --git a/gas/codeview.h b/gas/codeview.h
index def2a395748..2a3d8fc15e1 100644
--- a/gas/codeview.h
+++ b/gas/codeview.h
@@ -38,6 +38,7 @@
 
 #define CV_CFL_80386		0x03
 #define CV_CFL_X64		0xD0
+#define CV_CFL_ARM64		0xF6
 
 #define CHKSUM_TYPE_MD5		1
 
-- 
2.39.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] gas/testsuite: Add -gcodeview test for aarch64-w64-mingw32
  2023-01-26  0:38 [PATCH 1/2] gas: Add CodeView constant for aarch64 Mark Harmstone
@ 2023-01-26  0:38 ` Mark Harmstone
  2023-01-26  9:29   ` Jan Beulich
  2023-01-26  9:26 ` [PATCH 1/2] gas: Add CodeView constant for aarch64 Jan Beulich
  1 sibling, 1 reply; 6+ messages in thread
From: Mark Harmstone @ 2023-01-26  0:38 UTC (permalink / raw)
  To: binutils; +Cc: Mark Harmstone

This is a copy of the x86 gas -gcodeview test, with changes made for the
differing instruction lengths between x86 and aarch64.

---
 gas/testsuite/gas/aarch64/codeview-lines |   9 +
 gas/testsuite/gas/aarch64/codeview.exp   | 332 +++++++++++++++++++++++
 gas/testsuite/gas/aarch64/codeview1.s    |   7 +
 gas/testsuite/gas/aarch64/codeview2.s    |   2 +
 4 files changed, 350 insertions(+)
 create mode 100644 gas/testsuite/gas/aarch64/codeview-lines
 create mode 100644 gas/testsuite/gas/aarch64/codeview.exp
 create mode 100644 gas/testsuite/gas/aarch64/codeview1.s
 create mode 100644 gas/testsuite/gas/aarch64/codeview2.s

diff --git a/gas/testsuite/gas/aarch64/codeview-lines b/gas/testsuite/gas/aarch64/codeview-lines
new file mode 100644
index 00000000000..241c01dc16f
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/codeview-lines
@@ -0,0 +1,9 @@
+
+tmpdir/codeview-lines:     file format binary
+
+Contents of section .data:
+ 0000 00000000 00000000 10000000 00000000  ................
+ 0010 01000000 14000000 00000000 05000080  ................
+ 0020 18000000 02000000 1c000000 04000000  ................
+ 0030 01000080 08000000 02000080 00000000  ................
+ 0040 01000000 14000000 0c000000 07000080  ................
diff --git a/gas/testsuite/gas/aarch64/codeview.exp b/gas/testsuite/gas/aarch64/codeview.exp
new file mode 100644
index 00000000000..958bcdc835d
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/codeview.exp
@@ -0,0 +1,332 @@
+# Copyright (C) 2022-2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+if { ![istarget "aarch64-*-*"] } then {
+    return
+}
+
+if { ![istarget "*-*-mingw*"] && ![istarget "*-*-pe*"] } then {
+    return
+}
+
+proc read_subsection { fi } {
+    set data [read $fi 4]
+    binary scan $data i type
+
+    set data [read $fi 4]
+    binary scan $data i len
+
+    set data [read $fi $len]
+
+    if { [expr $len % 4] != 0 } {
+	seek $fi [expr 4 - ($len % 4)] current
+    }
+
+    return [list $type $data]
+}
+
+proc check_file_checksums { chksums string_table } {
+    set off 0
+
+    # check first file
+
+    set data [string range $chksums $off [expr $off + 3]]
+    incr off 4
+    binary scan $data i string_off
+
+    set filename [string range $string_table $string_off [expr [string first \000 $string_table $string_off] - 1]]
+
+    if ![string match "*codeview1.s" $filename] {
+	fail "Incorrect filename for first source file"
+    } else {
+	pass "Correct filename for first source file"
+    }
+
+    set data [string range $chksums $off $off]
+    incr off
+    binary scan $data c hash_length
+
+    if { $hash_length != 16 } {
+	fail "Incorrect hash length"
+    } else {
+	pass "Correct hash length"
+    }
+
+    set data [string range $chksums $off $off]
+    incr off
+    binary scan $data c hash_type
+
+    if { $hash_type != 1 } {
+	fail "Incorrect hash type"
+    } else {
+	pass "Correct hash type"
+    }
+
+    set data [string range $chksums $off [expr $off + $hash_length - 1]]
+    incr off $hash_length
+    binary scan $data H* hash
+
+    if ![string equal $hash "e396a2450f45912c0818c2b779ff05df"] {
+	fail "Incorrect MD5 hash"
+    } else {
+	pass "Correct MD5 hash"
+    }
+
+    # skip padding
+    if { [expr $off % 4] != 0 } {
+	incr off [expr 4 - ($off % 4)]
+    }
+
+    # check second file
+
+    set data [string range $chksums $off [expr $off + 3]]
+    incr off 4
+    binary scan $data i string_off
+
+    set filename [string range $string_table $string_off [expr [string first \000 $string_table $string_off] - 1]]
+
+    if ![string match "*codeview2.s" $filename] {
+	fail "Incorrect filename for second source file"
+    } else {
+	pass "Correct filename for second source file"
+    }
+
+    set data [string range $chksums $off $off]
+    incr off
+    binary scan $data c hash_length
+
+    if { $hash_length != 16 } {
+	fail "Incorrect hash length"
+    } else {
+	pass "Correct hash length"
+    }
+
+    set data [string range $chksums $off $off]
+    incr off
+    binary scan $data c hash_type
+
+    if { $hash_type != 1 } {
+	fail "Incorrect hash type"
+    } else {
+	pass "Correct hash type"
+    }
+
+    set data [string range $chksums $off [expr $off + $hash_length - 1]]
+    incr off $hash_length
+    binary scan $data H* hash
+
+    if ![string equal $hash "0374189e155c0a8aaa09c4ffdc23ec11"] {
+	fail "Incorrect MD5 hash"
+    } else {
+	pass "Correct MD5 hash"
+    }
+}
+
+proc check_lines { lines } {
+    global OBJDUMP
+    global srcdir
+    global subdir
+
+    set fi [open tmpdir/codeview-lines w]
+    fconfigure $fi -translation binary
+    puts -nonewline $fi $lines
+    close $fi
+
+    gas_host_run "$OBJDUMP -s --target=binary tmpdir/codeview-lines" ">& tmpdir/codeview-lines-text"
+
+    set exp [file_contents "$srcdir/$subdir/codeview-lines"]
+    set got [file_contents "tmpdir/codeview-lines-text"]
+
+    if [string equal $exp $got] {
+	pass "Correct lines info"
+    } else {
+	fail "Incorrect lines info"
+    }
+}
+
+proc check_objname { sym } {
+    binary scan $sym s type
+
+    if { $type != 0x1101 } {
+	fail "Symbol was not S_OBJNAME"
+	return
+    } else {
+	pass "Symbol was S_OBJNAME"
+    }
+
+    binary scan [string range $sym 2 5] i signature
+
+    if { $signature != 0 } {
+	fail "S_OBJNAME signature was not 0"
+	return
+    } else {
+	pass "S_OBJNAME signature was 0"
+    }
+
+    set filename [string range $sym 6 [expr [string first \000 $sym 6] - 1]]
+
+    if ![string match "*codeview1.o" $filename] {
+	fail "Incorrect object name in S_OBJNAME"
+    } else {
+	pass "Correct object name in S_OBJNAME"
+    }
+}
+
+proc check_compile3 { sym } {
+    binary scan $sym s type
+
+    if { $type != 0x113c } {
+	fail "Symbol was not S_COMPILE3"
+	return
+    } else {
+	pass "Symbol was S_COMPILE3"
+    }
+
+    set data [string range $sym 6 7]
+    binary scan $data s machine
+
+    if { $machine != 0xf6 } {
+	fail "Incorrect machine type in S_COMPILE3"
+    } else {
+	pass "Correct machine type in S_COMPILE3"
+    }
+
+    set assembler_name [string range $sym 24 [expr [string first \000 $sym 24] - 1]]
+
+    if ![string match "GNU AS *" $assembler_name] {
+	fail "Incorrect assembler name"
+    } else {
+	pass "Correct assembler name"
+    }
+}
+
+proc check_symbols { symbols } {
+    set off 0
+
+    # check S_OBJNAME record
+
+    set data [string range $symbols $off [expr $off + 1]]
+    incr off 2
+    binary scan $data s sym_len
+
+    set sym [string range $symbols $off [expr $off + $sym_len - 1]]
+    incr off $sym_len
+
+    check_objname $sym
+
+    # check S_COMPILE3 record
+
+    set data [string range $symbols $off [expr $off + 1]]
+    incr off 2
+    binary scan $data s sym_len
+
+    set sym [string range $symbols $off [expr $off + $sym_len - 1]]
+    incr off $sym_len
+
+    check_compile3 $sym
+}
+
+gas_run codeview1.s "-gcodeview -I $srcdir/$subdir -o tmpdir/codeview1.o" ">&dump.out"
+
+if { [file size "dump.out"] != 0 } {
+    fail "Failed to assemble codeview1.s"
+    return
+} else {
+    pass "Assembled codeview1.s"
+}
+
+gas_host_run "$OBJCOPY --dump-section .debug\\\$S=tmpdir/codeview-debug tmpdir/codeview1.o" ">&dump.out"
+
+if { [file size "dump.out"] != 0 } {
+    fail "Failed to extract .debug\$S section from codeview1.o"
+    return
+} else {
+    pass "Extracted .debug\$S section from codeview1.o"
+}
+
+set fi [open tmpdir/codeview-debug]
+fconfigure $fi -translation binary
+
+# check signature
+
+set data [read $fi 4]
+binary scan $data i cv_sig
+
+if { $cv_sig != 4 } {
+    fail "Invalid CodeView signature"
+    close $fi
+    return
+} else {
+    pass "Correct CodeView signature"
+}
+
+# read string table (DEBUG_S_STRINGTABLE)
+
+set result [read_subsection $fi]
+
+if { [lindex $result 0] != 0xf3 } {
+    fail "Subsection was not string table"
+    close $fi
+    return
+} else {
+    pass "Read string table"
+}
+
+set string_table [lindex $result 1]
+
+# read file checksums (DEBUG_S_FILECHKSMS)
+
+set result [read_subsection $fi]
+
+if { [lindex $result 0] != 0xf4 } {
+    fail "Subsection was not file checksums"
+    close $fi
+    return
+} else {
+    pass "Read file checksums"
+}
+
+check_file_checksums [lindex $result 1] $string_table
+
+# read line info (DEBUG_S_LINES)
+
+set result [read_subsection $fi]
+
+if { [lindex $result 0] != 0xf2 } {
+    fail "Subsection was not line info"
+    close $fi
+    return
+} else {
+    pass "Read line info"
+}
+
+check_lines [lindex $result 1]
+
+# read CodeView symbols (DEBUG_S_SYMBOLS)
+
+set result [read_subsection $fi]
+
+if { [lindex $result 0] != 0xf1 } {
+    fail "Subsection was not symbols"
+    close $fi
+    return
+} else {
+    pass "Read symbols"
+}
+
+check_symbols [lindex $result 1]
+
+close $fi
diff --git a/gas/testsuite/gas/aarch64/codeview1.s b/gas/testsuite/gas/aarch64/codeview1.s
new file mode 100644
index 00000000000..15626c5c459
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/codeview1.s
@@ -0,0 +1,7 @@
+.text
+
+.global main
+main:
+	nop
+	.include "codeview2.s"
+	nop
diff --git a/gas/testsuite/gas/aarch64/codeview2.s b/gas/testsuite/gas/aarch64/codeview2.s
new file mode 100644
index 00000000000..c4e2dbcb132
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/codeview2.s
@@ -0,0 +1,2 @@
+nop
+nop
-- 
2.39.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] gas: Add CodeView constant for aarch64
  2023-01-26  0:38 [PATCH 1/2] gas: Add CodeView constant for aarch64 Mark Harmstone
  2023-01-26  0:38 ` [PATCH 2/2] gas/testsuite: Add -gcodeview test for aarch64-w64-mingw32 Mark Harmstone
@ 2023-01-26  9:26 ` Jan Beulich
  2023-01-26 12:41   ` Mark Harmstone
  1 sibling, 1 reply; 6+ messages in thread
From: Jan Beulich @ 2023-01-26  9:26 UTC (permalink / raw)
  To: Mark Harmstone; +Cc: binutils

On 26.01.2023 01:38, Mark Harmstone wrote:
> Adds the correct constant to the S_COMPILE3 CodeView record when
> assembling aarch64-w64-mingw32 with the -gcodeview flag.

I'd be happy to approve this, but I'd really like to know where this number
is coming from. Web search looks to produce results only for properly
outdated or LLVM pages, neither of which can really be taken as a canonical
reference for something with MS origin. (I find it particularly interesting
that the wikipedia page on CodeView says "Operating system	MS-DOS",
calling out 386 mode and monochrome monitor support as something noteworthy.
Nevertheless at the bottom there is "This page was last edited on
25 December 2022, at 04:29 (UTC).")

Jan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] gas/testsuite: Add -gcodeview test for aarch64-w64-mingw32
  2023-01-26  0:38 ` [PATCH 2/2] gas/testsuite: Add -gcodeview test for aarch64-w64-mingw32 Mark Harmstone
@ 2023-01-26  9:29   ` Jan Beulich
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Beulich @ 2023-01-26  9:29 UTC (permalink / raw)
  To: Mark Harmstone; +Cc: binutils

On 26.01.2023 01:38, Mark Harmstone wrote:
> This is a copy of the x86 gas -gcodeview test, with changes made for the
> differing instruction lengths between x86 and aarch64.

Hmm, probably okay for the time being, but going this route doesn't really
scale. For Dwarf we also have testcases covering multiple architectures in
one go ...

Jan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] gas: Add CodeView constant for aarch64
  2023-01-26  9:26 ` [PATCH 1/2] gas: Add CodeView constant for aarch64 Jan Beulich
@ 2023-01-26 12:41   ` Mark Harmstone
  2023-01-26 12:53     ` Jan Beulich
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Harmstone @ 2023-01-26 12:41 UTC (permalink / raw)
  To: Jan Beulich; +Cc: binutils

Hi Jan,

 > I'd be happy to approve this, but I'd really like to know where this number
 > is coming from.

Have a look at the top of gas/codeview.h, which includes the URL of the GitHub
repository this comes from.

 > (I find it particularly interesting
 > that the wikipedia page on CodeView says "Operating system  MS-DOS",
 > calling out 386 mode and monochrome monitor support as something noteworthy.
 > Nevertheless at the bottom there is "This page was last edited on
 > 25 December 2022, at 04:29 (UTC).")

Yes, CodeView the program is long dead, but its format lives on in the PDBs
generated by MSVC.

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] gas: Add CodeView constant for aarch64
  2023-01-26 12:41   ` Mark Harmstone
@ 2023-01-26 12:53     ` Jan Beulich
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Beulich @ 2023-01-26 12:53 UTC (permalink / raw)
  To: Mark Harmstone; +Cc: binutils

On 26.01.2023 13:41, Mark Harmstone wrote:
>  > I'd be happy to approve this, but I'd really like to know where this number
>  > is coming from.
> 
> Have a look at the top of gas/codeview.h, which includes the URL of the GitHub
> repository this comes from.

Thanks. Having looked there, the patch is okay to commit.

Jan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-01-26 12:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26  0:38 [PATCH 1/2] gas: Add CodeView constant for aarch64 Mark Harmstone
2023-01-26  0:38 ` [PATCH 2/2] gas/testsuite: Add -gcodeview test for aarch64-w64-mingw32 Mark Harmstone
2023-01-26  9:29   ` Jan Beulich
2023-01-26  9:26 ` [PATCH 1/2] gas: Add CodeView constant for aarch64 Jan Beulich
2023-01-26 12:41   ` Mark Harmstone
2023-01-26 12:53     ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).