From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 601A1385800F for ; Tue, 21 Nov 2023 22:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 601A1385800F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 601A1385800F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605232; cv=none; b=SWc9x8fw37HGm2Wse0O3zsvyri9p0exJXbIpwjX1hgVrbAqkFfQHrW9leQek/FRQk7n+0abqvTO2q21bcP6dzasfujJUxNAkbxnzzgUWJZlvnWcUGnpMHo4fihuk/PZU2FCwbu5oBKvs4FV7LWfBfn3SnTJUnEwQu+sTYpfVyoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605232; c=relaxed/simple; bh=RJRF4jQ5sFvR9dnsnlmKYvo+hrORD4LAp8654PaSlS8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=cpb6KbJsIBBNI2SlqY/szx3PFrB0pLBjCGpKqmHu1HQutSOztkA2dFWXtZ0AieImnB5oB66LhUK2HLW6kMf5CxjPHw+9oWavdrJha7spU7g456Ie59FILRcFbVlh7XrzC/0k8AzcRN7gT8E8BP0fbZRf7xqItPAaFjIhbYkl9ys= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700605226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gGDfKCwiRqcQ3M7tQE1zNzlpOhmyDNNvI/eOwTkj6UM=; b=bK4X2nCwyNmlrjj7Hg3akIG1JREcWGnrkuAmb8zIV8x8qwkWKajUppKPGdR1MSU5bTHMpF yEEY9y9QBiXUh0VnxVibK9j7oPCwapX9tZRrc2J1xniSeslT3IBYeOjBCJZxFfMLjQF1Pq EdE1Sib9wI4s8dqqQcmIX3TOiag4d4E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-442--uasDe6zNm-aYAxFFuPibA-1; Tue, 21 Nov 2023 17:20:24 -0500 X-MC-Unique: -uasDe6zNm-aYAxFFuPibA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 93915821C21; Tue, 21 Nov 2023 22:20:23 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C0BA492BFA; Tue, 21 Nov 2023 22:20:23 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, binutils@sourceware.org Cc: Nick Clifton , Simon Sobisch , David Malcolm Subject: [PATCH] binutils: v2: experimental use of libdiagnostics in gas Date: Tue, 21 Nov 2023 17:20:19 -0500 Message-Id: <20231121222019.646253-7-dmalcolm@redhat.com> In-Reply-To: <20231121222019.646253-1-dmalcolm@redhat.com> References: <20231106222959.2707741-1-dmalcolm@redhat.com> <20231121222019.646253-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Changed in v2: * updated for change from diagnostic_location_t to const diagnostic_physical_location * * fix #if USE_DIAGNOSTICS to retain context and listing code Output from the example below with v2 is now: testsuite/gas/all/warn-1.s:3: warning: a warning message 3 | .warning "a warning message" ;# { dg-warning "Warning: a warning= message" } testsuite/gas/all/warn-1.s:4: error: .warning argument must be a string 4 | .warning a warning message ;# { dg-error "Error: .warning argu= ment must be a string" } testsuite/gas/all/warn-1.s:5: warning: .warning directive invoked in source= file 5 | .warning ;# { dg-warning "Warning: .warning = directive invoked in source file" } testsuite/gas/all/warn-1.s:6: warning: .warning directive invoked in source= file 6 | .warning ".warning directive invoked in source file" ;# { dg-war= ning "Warning: .warning directive invoked in source file" } testsuite/gas/all/warn-1.s:7: warning:=20 7 | .warning "" ;# { dg-warning "Warning: " } and there's also now a way to toggle quoting of the source code (perhaps for use in the testsuite) Blurb from v1: Here's a patch for gas in binutils that makes it use libdiagnostics (with some nasty hardcoded paths to specific places on my hard drive to make it easier to develop the API). For now this hardcodes adding two sinks: a text sink on stderr, and also a SARIF output to stderr (which happens after all regular output). For example, without this patch: gas testsuite/gas/all/warn-1.s emits: VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV= V testsuite/gas/all/warn-1.s: Assembler messages: testsuite/gas/all/warn-1.s:3: Warning: a warning message testsuite/gas/all/warn-1.s:4: Error: .warning argument must be a string testsuite/gas/all/warn-1.s:5: Warning: .warning directive invoked in source= file testsuite/gas/all/warn-1.s:6: Warning: .warning directive invoked in source= file testsuite/gas/all/warn-1.s:7: Warning: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^= ^ whereas with this patch: LD_LIBRARY_PATH=3D/home/david/coding-3/gcc-newgit-canvas-2023/build/gcc .= /as-new testsuite/gas/all/warn-1.s emits: VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV= V testsuite/gas/all/warn-1.s:3: warning: a warning message 3 | .warning "a warning message" ;# { dg-warning "Warning: a warning= message" } | testsuite/gas/all/warn-1.s:4: error: .warning argument must be a string 4 | .warning a warning message ;# { dg-error "Error: .warning argu= ment must be a string" } | testsuite/gas/all/warn-1.s:5: warning: .warning directive invoked in source= file 5 | .warning ;# { dg-warning "Warning: .warning = directive invoked in source file" } | testsuite/gas/all/warn-1.s:6: warning: .warning directive invoked in source= file 6 | .warning ".warning directive invoked in source file" ;# { dg-war= ning "Warning: .warning directive invoked in source file" } | testsuite/gas/all/warn-1.s:7: warning: 7 | .warning "" ;# { dg-warning "Warning: " } | =09{"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/mast= er/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [{"tool":= {"driver": {"rules": []}}, "invocations": [{"executionSuccessful": true, "= toolExecutionNotifications": []}], "originalUriBaseIds": {"PWD": {"uri": "f= ile:///home/david/coding-3/binutils-gdb/gas/"}}, "artifacts": [{"location":= {"uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD"}, "contents": {"t= ext": ";# Test .warning directive.\n;# { dg-do assemble }\n .warning \"a wa= rning message\"\t;# { dg-warning \"Warning: a warning message\" }\n .warnin= g a warning message\t;# { dg-error \"Error: .warning argument must be a str= ing\" }\n .warning\t\t\t;# { dg-warning \"Warning: .warning directive invok= ed in source file\" }\n .warning \".warning directive invoked in source fil= e\"\t;# { dg-warning \"Warning: .warning directive invoked in source file\"= }\n .warning \"\"\t\t\t;# { dg-warning \"Warning: \" }\n"}}], "results": [= {"ruleId": "warning", "level": "warning", "message": {"text": "a warning me= ssage"}, "locations": [{"physicalLocation": {"artifactLocation": {"uri": "t= estsuite/gas/all/warn-1.s", "uriBaseId": "PWD"}, "region": {"startLine": 3,= "startColumn": 0, "endColumn": 1}, "contextRegion": {"startLine": 3, "snip= pet": {"text": " .warning \"a warning message\"\t;# { dg-warning \"Warning:= a warning message\" }\n"}}}}], "relatedLocations": [{"physicalLocation": {= "artifactLocation": {"uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD= "}, "region": {"startLine": 4, "startColumn": 0, "endColumn": 1}, "contextR= egion": {"startLine": 4, "snippet": {"text": " .warning a warning message\t= ;# { dg-error \"Error: .warning argument must be a string\" }\n"}}}, "messa= ge": {"text": ".warning argument must be a string"}}, {"physicalLocation": = {"artifactLocation": {"uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PW= D"}, "region": {"startLine": 5, "startColumn": 0, "endColumn": 1}, "context= Region": {"startLine": 5, "snippet": {"text": " .warning\t\t\t;# { dg-warni= ng \"Warning: .warning directive invoked in source file\" }\n"}}}, "message= ": {"text": ".warning directive invoked in source file"}}, {"physicalLocati= on": {"artifactLocation": {"uri": "testsuite/gas/all/warn-1.s", "uriBaseId"= : "PWD"}, "region": {"startLine": 6, "startColumn": 0, "endColumn": 1}, "co= ntextRegion": {"startLine": 6, "snippet": {"text": " .warning \".warning di= rective invoked in source file\"\t;# { dg-warning \"Warning: .warning direc= tive invoked in source file\" }\n"}}}, "message": {"text": ".warning direct= ive invoked in source file"}}, {"physicalLocation": {"artifactLocation": {"= uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD"}, "region": {"startL= ine": 7, "startColumn": 0, "endColumn": 1}, "contextRegion": {"startLine": = 7, "snippet": {"text": " .warning \"\"\t\t\t;# { dg-warning \"Warning: \" }= \n"}}}, "message": {"text": ""}}]}]}]} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^= ^ For reference, running that SARIF through "python -m json.tool" to prettyify it gives: VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV= V { "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/mast= er/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [ { "tool": { "driver": { "rules": [] } }, "invocations": [ { "executionSuccessful": true, "toolExecutionNotifications": [] } ], "originalUriBaseIds": { "PWD": { "uri": "file:///home/david/coding-3/binutils-gdb/gas/" } }, "artifacts": [ { "location": { "uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD" }, "contents": { "text": ";# Test .warning directive.\n;# { dg-do as= semble }\n .warning \"a warning message\"\t;# { dg-warning \"Warning: a war= ning message\" }\n .warning a warning message\t;# { dg-error \"Error: .warn= ing argument must be a string\" }\n .warning\t\t\t;# { dg-warning \"Warning= : .warning directive invoked in source file\" }\n .warning \".warning direc= tive invoked in source file\"\t;# { dg-warning \"Warning: .warning directiv= e invoked in source file\" }\n .warning \"\"\t\t\t;# { dg-warning \"Warning= : \" }\n" } } ], "results": [ { "ruleId": "warning", "level": "warning", "message": { "text": "a warning message" }, "locations": [ { "physicalLocation": { "artifactLocation": { "uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD" }, "region": { "startLine": 3, "startColumn": 0, "endColumn": 1 }, "contextRegion": { "startLine": 3, "snippet": { "text": " .warning \"a warning mess= age\"\t;# { dg-warning \"Warning: a warning message\" }\n" } } } } ], "relatedLocations": [ { "physicalLocation": { "artifactLocation": { "uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD" }, "region": { "startLine": 4, "startColumn": 0, "endColumn": 1 }, "contextRegion": { "startLine": 4, "snippet": { "text": " .warning a warning messag= e\t;# { dg-error \"Error: .warning argument must be a string\" }\n" } } }, "message": { "text": ".warning argument must be a string= " } }, { "physicalLocation": { "artifactLocation": { "uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD" }, "region": { "startLine": 5, "startColumn": 0, "endColumn": 1 }, "contextRegion": { "startLine": 5, "snippet": { "text": " .warning\t\t\t;# { dg-war= ning \"Warning: .warning directive invoked in source file\" }\n" } } }, "message": { "text": ".warning directive invoked in sour= ce file" } }, { "physicalLocation": { "artifactLocation": { "uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD" }, "region": { "startLine": 6, "startColumn": 0, "endColumn": 1 }, "contextRegion": { "startLine": 6, "snippet": { "text": " .warning \".warning direc= tive invoked in source file\"\t;# { dg-warning \"Warning: .warning directiv= e invoked in source file\" }\n" } } }, "message": { "text": ".warning directive invoked in sour= ce file" } }, { "physicalLocation": { "artifactLocation": { "uri": "testsuite/gas/all/warn-1.s", "uriBaseId": "PWD" }, "region": { "startLine": 7, "startColumn": 0, "endColumn": 1 }, "contextRegion": { "startLine": 7, "snippet": { "text": " .warning \"\"\t\t\t;# { d= g-warning \"Warning: \" }\n" } } }, "message": { "text": "" } } ] } ] } ] } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^= ^ gas/ChangeLog: =09* Makefile.am (GASLIBS): Add nasty hack with hardcoded path =09on my hard drive. =09* Makefile.in (GASLIBS): Likewise. =09* as.c (gas_init): Call messages_init. =09(main): Call messages_end. =09* as.h (messages_init): New decl. =09(messages_end): New decl. =09* messages.c (USE_LIBDIAGNOSTICS): New define. =09Add #include with nasty hardcoded path. =09(diag_mgr): New. =09(messages_init): New. =09(messages_end): New. =09(as_warn_internal): Add support for libdiagnostics. =09(as_bad_internal): Likewise. --- gas/Makefile.am | 3 ++- gas/Makefile.in | 4 +++- gas/as.c | 3 +++ gas/as.h | 3 +++ gas/messages.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 2 deletions(-) diff --git a/gas/Makefile.am b/gas/Makefile.am index 0e98ca3ec85..fe92997129c 100644 --- a/gas/Makefile.am +++ b/gas/Makefile.am @@ -408,7 +408,8 @@ AM_CPPFLAGS =3D -I. -I$(srcdir) -I../bfd -I$(srcdir)/co= nfig \ # How to link with both our special library facilities # and the system's installed libraries. =20 -GASLIBS =3D @OPCODES_LIB@ ../bfd/libbfd.la ../libiberty/libiberty.a +# FIXME: +GASLIBS =3D @OPCODES_LIB@ ../bfd/libbfd.la ../libiberty/libiberty.a /home/= david/coding-3/gcc-newgit-canvas-2023/build/gcc/libdiagnostics.so =20 # Files to be copied away after each stage in building. STAGESTUFF =3D *.@OBJEXT@ $(noinst_PROGRAMS) diff --git a/gas/Makefile.in b/gas/Makefile.in index fae3a47c144..2161d68f9c7 100644 --- a/gas/Makefile.in +++ b/gas/Makefile.in @@ -885,7 +885,9 @@ AM_CPPFLAGS =3D -I. -I$(srcdir) -I../bfd -I$(srcdir)/co= nfig \ =20 # How to link with both our special library facilities # and the system's installed libraries. -GASLIBS =3D @OPCODES_LIB@ ../bfd/libbfd.la ../libiberty/libiberty.a + +# FIXME: +GASLIBS =3D @OPCODES_LIB@ ../bfd/libbfd.la ../libiberty/libiberty.a /home/= david/coding-3/gcc-newgit-canvas-2023/build/gcc/libdiagnostics.so =20 # Files to be copied away after each stage in building. STAGESTUFF =3D *.@OBJEXT@ $(noinst_PROGRAMS) diff --git a/gas/as.c b/gas/as.c index 6839c841588..2a8ce3734a0 100644 --- a/gas/as.c +++ b/gas/as.c @@ -1300,6 +1300,7 @@ gas_early_init (int *argcp, char ***argvp) static void gas_init (void) { + messages_init (); symbol_begin (); frag_init (); subsegs_begin (); @@ -1486,6 +1487,8 @@ main (int argc, char ** argv) =20 input_scrub_end (); =20 + messages_end (); + /* Use xexit instead of return, because under VMS environments they may not place the same interpretation on the value given. */ if (had_errors () !=3D 0) diff --git a/gas/as.h b/gas/as.h index 99ffe77afd2..9d878a87df5 100644 --- a/gas/as.h +++ b/gas/as.h @@ -474,6 +474,9 @@ void as_bad_value_out_of_range (const char *, offsetT= , offsetT, offsetT, void print_version_id (void); char * app_push (void); =20 +void messages_init (void); +void messages_end (void); + /* Number of littlenums required to hold an extended precision number.=09*= / #define MAX_LITTLENUMS 6 =20 diff --git a/gas/messages.c b/gas/messages.c index 7c018acf69f..1854560dae7 100644 --- a/gas/messages.c +++ b/gas/messages.c @@ -21,6 +21,14 @@ #include #include =20 +// FIXME: do some configury thing for this +#define USE_LIBDIAGNOSTICS 1 + +#if USE_LIBDIAGNOSTICS +// FIXME: need to fix this path, obviously +#include "/home/david/coding-3/gcc-newgit-canvas-2023/src/gcc/libdiagnosti= cs.h" +#endif + /* If the system doesn't provide strsignal, we get it defined in libiberty but no declaration is supplied. Because, reasons. */ #if !defined (HAVE_STRSIGNAL) && !defined (strsignal) @@ -101,6 +109,29 @@ had_warnings (void) return warning_count; } =20 +#if USE_LIBDIAGNOSTICS +static diagnostic_manager *diag_mgr; +#endif + +void messages_init (void) +{ +#if USE_LIBDIAGNOSTICS + diag_mgr =3D diagnostic_manager_new (); + diagnostic_manager_add_text_sink (diag_mgr, stderr, +=09=09=09=09 DIAGNOSTIC_COLORIZE_IF_TTY); + diagnostic_manager_add_sarif_sink (diag_mgr, stderr, +=09=09=09=09 DIAGNOSTIC_SARIF_VERSION_2_1_0); +#endif +} + +void messages_end (void) +{ +#if USE_LIBDIAGNOSTICS + diagnostic_manager_release (diag_mgr); + diag_mgr =3D NULL; +#endif +} + /* Nonzero if we've hit a 'bad error', and should not write an obj file, and exit with a nonzero error code. */ =20 @@ -182,6 +213,20 @@ as_warn_internal (const char *file, unsigned int line,= char *buffer) context =3D true; } =20 +#if USE_LIBDIAGNOSTICS + const diagnostic_file *file_obj + =3D diagnostic_manager_new_file (diag_mgr, file, NULL); + + const diagnostic_physical_location *loc + =3D diagnostic_manager_new_location_from_file_and_line (diag_mgr, +=09=09=09=09=09=09=09 file_obj, +=09=09=09=09=09=09=09 line); + + diagnostic *d =3D diagnostic_begin (diag_mgr, +=09=09=09=09 DIAGNOSTIC_LEVEL_WARNING); + diagnostic_set_location (d, loc); + diagnostic_finish (d, "%s", buffer); +#else identify (file); if (file) { @@ -192,6 +237,7 @@ as_warn_internal (const char *file, unsigned int line, = char *buffer) } else fprintf (stderr, "%s%s\n", _("Warning: "), buffer); +#endif /* #else clause of #if USE_LIBDIAGNOSTICS */ =20 if (context) as_report_context (); @@ -256,6 +302,19 @@ as_bad_internal (const char *file, unsigned int line, = char *buffer) context =3D true; } =20 +#if USE_LIBDIAGNOSTICS + const diagnostic_file *file_obj + =3D diagnostic_manager_new_file (diag_mgr, file, NULL); + const diagnostic_physical_location *loc + =3D diagnostic_manager_new_location_from_file_and_line (diag_mgr, +=09=09=09=09=09=09=09 file_obj, +=09=09=09=09=09=09=09 line); + + diagnostic *d =3D diagnostic_begin (diag_mgr, +=09=09=09=09 DIAGNOSTIC_LEVEL_ERROR); + diagnostic_set_location (d, loc); + diagnostic_finish (d, "%s", buffer); +#else identify (file); if (file) { @@ -266,6 +325,7 @@ as_bad_internal (const char *file, unsigned int line, c= har *buffer) } else fprintf (stderr, "%s%s\n", _("Error: "), buffer); +#endif /* #else clause of #if USE_LIBDIAGNOSTICS */ =20 if (context) as_report_context (); --=20 2.26.3