From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 82a4OrXaFGPZOTMAWB0awg (envelope-from ) for ; Sun, 04 Sep 2022 13:04:53 -0400 Received: by simark.ca (Postfix, from userid 112) id E4C931E4A7; Sun, 4 Sep 2022 13:04:53 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=PAfbJo3T; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 simark.ca (Postfix) with ESMTPS id 787911E222 for ; Sun, 4 Sep 2022 13:04:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95AFC3856947 for ; Sun, 4 Sep 2022 17:04:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95AFC3856947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1662311091; bh=b7x3BS4T1jfVEPNs2JjWW4V4pdZouMgTLrMOpHAAkyg=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=PAfbJo3T9c50tKeNDpqdyIfee6fLDv5wA6s9YXs6tXgA9gN5PQt11K2CUoTctkYz3 m/j3qvMwZHOeY9NzdkrpaiDnko3KbBJOZ8FGjw9aEjFX7lMBIrurOSsqcqU48X4o9S CiQc0jAH6vD3JoHfwt4xArB7emMs2fUtSvJFM0w8= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7C89E38582B0 for ; Sun, 4 Sep 2022 17:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7C89E38582B0 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-341-djcI5XDBPqioAvm1IsOgVA-1; Sun, 04 Sep 2022 13:04:20 -0400 X-MC-Unique: djcI5XDBPqioAvm1IsOgVA-1 Received: by mail-wm1-f70.google.com with SMTP id c64-20020a1c3543000000b003a61987ffb3so4210431wma.6 for ; Sun, 04 Sep 2022 10:04:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=Ws2Ewt3tsYJVb9uKnobv/r7WpyIbJrFy1cQbg8cohOc=; b=300iOiw8s8qq0KptJwvyYq/n6z+YexeMreCNdvVh84rbH6AIR6lGAotIkjXt901yxV 6scgzO5WIW+o70r9C24wi4kCHi4LOrkx/RRoroRnnEpkqRGafBUyJflDtC9g//nNGsAm J/e+e0o7Q40V/khwjxISTi7lPdCKobM8t8zXUGkhHrAedYqgIZCwbepLxnPeM2C30Pyo X/+eIJCa9zPh/MSsNeF1CmCxqn5tzAuBu18YOXiAGzi98ASeZhsNbYP3Hhnv4g7V3aoV mKknFw/OhxAOxlROodVCYK3/xU8oAFtwjnDVuHZ2JzWxcC9avTK07haCZ+nU12mxj/7A TlXw== X-Gm-Message-State: ACgBeo0x2XDxa8LrcH3TVg2Rya8M/BzDeO7y0YR5RBzS7fW/F8xso0YF XmyJ+ptwKJ+fKGF/aC36YA3BMC/zTO5hITZuv4JhfjieV3O7QjbdrT5U3ekqoE98cajflr+4217 MRZC2VBO59MTVHD3raNb/MA== X-Received: by 2002:adf:9d8b:0:b0:228:5e43:7e0a with SMTP id p11-20020adf9d8b000000b002285e437e0amr3835468wre.687.1662311059676; Sun, 04 Sep 2022 10:04:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7IOe55d44SeRwovB2A7hLfPi3+O8DMLY9cTjwFmnNkBCr02r1fdkP0CNsd6tVDwcpkrLiB8Q== X-Received: by 2002:adf:9d8b:0:b0:228:5e43:7e0a with SMTP id p11-20020adf9d8b000000b002285e437e0amr3835454wre.687.1662311059314; Sun, 04 Sep 2022 10:04:19 -0700 (PDT) Received: from localhost ([31.111.84.229]) by smtp.gmail.com with ESMTPSA id az3-20020a05600c600300b003a6a3595edasm8479162wmb.27.2022.09.04.10.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Sep 2022 10:04:18 -0700 (PDT) Date: Sun, 4 Sep 2022 18:04:17 +0100 To: Jan-Benedict Glaw Subject: Re: [PUSHED] sim: fixes for libopcodes styled disassembler Message-ID: <20220904170417.GA745711@redhat.com> References: <20220404214632.1103903-1-aburgess@redhat.com> <20220903065732.eb4sqco3zuk53ztu@lug-owl.de> MIME-Version: 1.0 In-Reply-To: <20220903065732.eb4sqco3zuk53ztu@lug-owl.de> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 18:03:10 up 12 days, 6:37, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" * Jan-Benedict Glaw [2022-09-03 08:57:32 +0200]: > On Mon, 2022-04-04 22:46:32 +0100, Andrew Burgess via Gdb-patches wrote: > > I've gone ahead and pushed the patch below without review, despite it > > being non-trivial. I stupidly managed to break several sim targets, > > and I wanted to undo the breakage asap. > >=20 > > Despite being quite large, I hope nothing in here is too > > controversial. However, if there is any feedback, do please leave it > > and I'll be happy to fix any issues in a follow up patch. > >=20 > > Sorry for the breakage, and thank you for your understanding. >=20 > .../configure --prefix=3D... --target=3Dsparc-linux > make V=3D1 all-gdb >=20 > [...] > rm -f gdb > g++ -g -O2 -pthread \ > -o gdb gdb.o ada-exp.o ada-lang.o ada-tasks.o ada-typeprint.o ada= -valprint.o ada-varobj.o addrmap.o agent.o alloc.o annotate.o arch-utils.o = async-event.o auto-load.o auxv.o ax-gdb.o ax-general.o bcache.o bfd-target.= o block.o blockframe.o break-catch-exec.o break-catch-fork.o break-catch-lo= ad.o break-catch-sig.o break-catch-syscall.o break-catch-throw.o breakpoint= .o bt-utils.o btrace.o build-id.o buildsym-legacy.o buildsym.o c-exp.o c-la= ng.o c-typeprint.o c-valprint.o c-varobj.o charset.o cli-out.o cli/cli-cmds= .o cli/cli-decode.o cli/cli-dump.o cli/cli-interp.o cli/cli-logging.o cli/c= li-option.o cli/cli-script.o cli/cli-setshow.o cli/cli-style.o cli/cli-util= s.o coff-pe-read.o coffread.o compile/compile-c-support.o compile/compile-c= -symbols.o compile/compile-c-types.o compile/compile-cplus-symbols.o compil= e/compile-cplus-types.o compile/compile-loc2c.o compile/compile-object-load= .o compile/compile-object-run.o compile/compile.o complaints.o completer.o = copying.o corefile.o corelow.o cp-abi.o cp-name-parser.o cp-namespace.o cp-= support.o cp-valprint.o ctfread.o d-exp.o d-lang.o d-namespace.o d-valprint= .o dbxread.o dcache.o debug.o debuginfod-support.o dictionary.o disasm-self= tests.o disasm.o displaced-stepping.o dtrace-probe.o dummy-frame.o dwarf2/a= bbrev-cache.o dwarf2/abbrev.o dwarf2/attribute.o dwarf2/comp-unit-head.o dw= arf2/cooked-index.o dwarf2/cu.o dwarf2/dwz.o dwarf2/expr.o dwarf2/frame-tai= lcall.o dwarf2/frame.o dwarf2/index-cache.o dwarf2/index-common.o dwarf2/in= dex-write.o dwarf2/leb.o dwarf2/line-header.o dwarf2/loc.o dwarf2/macro.o d= warf2/read.o dwarf2/section.o dwarf2/stringify.o elf-none-tdep.o elfread.o = eval.o event-top.o exceptions.o exec.o expprint.o extension.o f-exp.o f-lan= g.o f-typeprint.o f-valprint.o filename-seen-cache.o filesystem.o findcmd.o= findvar.o frame-base.o frame-unwind.o frame.o gcore-elf.o gcore.o gdb-dema= ngle.o gdb_bfd.o gdbarch-selftests.o gdbtypes.o gmp-utils.o gnu-v2-abi.o gn= u-v3-abi.o go-exp.o go-lang.o go-typeprint.o go-valprint.o guile/guile.o in= f-child.o inf-loop.o infcall.o infcmd.o inferior.o inflow.o infrun.o inline= -frame.o interps.o jit.o language.o linespec.o linux-tdep.o location.o m2-e= xp.o m2-lang.o m2-typeprint.o m2-valprint.o macrocmd.o macroexp.o macroscop= e.o macrotab.o main.o maint-test-options.o maint-test-settings.o maint.o md= ebugread.o mem-break.o memattr.o memory-map.o memrange.o memtag.o mi/mi-cmd= -break.o mi/mi-cmd-catch.o mi/mi-cmd-disas.o mi/mi-cmd-env.o mi/mi-cmd-file= .o mi/mi-cmd-info.o mi/mi-cmd-stack.o mi/mi-cmd-target.o mi/mi-cmd-var.o mi= /mi-cmds.o mi/mi-common.o mi/mi-console.o mi/mi-getopt.o mi/mi-interp.o mi/= mi-main.o mi/mi-out.o mi/mi-parse.o mi/mi-symbol-cmds.o minidebug.o minsyms= .o mipsread.o namespace.o objc-lang.o objfiles.o observable.o opencl-lang.o= osabi.o osdata.o p-exp.o p-lang.o p-typeprint.o p-valprint.o parse.o posix= -hdep.o printcmd.o probe.o process-stratum-target.o producer.o progspace-an= d-thread.o progspace.o prologue-value.o psymtab.o python/python.o ravenscar= -thread.o record-btrace.o record-full.o record.o regcache-dump.o regcache.o= reggroups.o remote-fileio.o remote-notif.o remote-sim.o remote.o reverse.o= run-on-main-thread.o rust-lang.o rust-parse.o selftest-arch.o sentinel-fra= me.o ser-base.o ser-event.o ser-pipe.o ser-tcp.o ser-uds.o ser-unix.o seria= l.o skip.o solib-svr4.o solib-target.o solib.o source-cache.o source.o spar= c-linux-tdep.o sparc-ravenscar-thread.o sparc-tdep.o sparc64-linux-tdep.o s= parc64-tdep.o split-name.o stabsread.o stack.o stap-probe.o std-regs.o symf= ile-debug.o symfile-mem.o symfile.o symmisc.o symtab.o target-connection.o = target-dcache.o target-descriptions.o target-float.o target-memory.o target= .o target/target.o target/waitstatus.o test-target.o thread-iter.o thread.o= tid-parse.o top.o tracectf.o tracefile-tfile.o tracefile.o tracepoint.o tr= ad-frame.o tramp-frame.o tui/tui-command.o tui/tui-data.o tui/tui-disasm.o = tui/tui-file.o tui/tui-hooks.o tui/tui-interp.o tui/tui-io.o tui/tui-layout= .o tui/tui-location.o tui/tui-out.o tui/tui-regs.o tui/tui-source.o tui/tui= -stack.o tui/tui-win.o tui/tui-wingeneral.o tui/tui-winsource.o tui/tui.o t= ype-stack.o typeprint.o ui-file.o ui-out.o ui-style.o unittests/array-view-= selftests.o unittests/child-path-selftests.o unittests/cli-utils-selftests.= o unittests/command-def-selftests.o unittests/common-utils-selftests.o unit= tests/copy_bitwise-selftests.o unittests/enum-flags-selftests.o unittests/e= nviron-selftests.o unittests/filtered_iterator-selftests.o unittests/format= _pieces-selftests.o unittests/function-view-selftests.o unittests/gdb_tilde= _expand-selftests.o unittests/gmp-utils-selftests.o unittests/intrusive_lis= t-selftests.o unittests/lookup_name_info-selftests.o unittests/main-thread-= selftests.o unittests/memory-map-selftests.o unittests/memrange-selftests.o= unittests/mkdir-recursive-selftests.o unittests/observable-selftests.o uni= ttests/offset-type-selftests.o unittests/optional-selftests.o unittests/pac= ked-selftests.o unittests/parallel-for-selftests.o unittests/parse-connecti= on-spec-selftests.o unittests/path-join-selftests.o unittests/ptid-selftest= s.o unittests/rsp-low-selftests.o unittests/scoped_fd-selftests.o unittests= /scoped_ignore_signal-selftests.o unittests/scoped_mmap-selftests.o unittes= ts/scoped_restore-selftests.o unittests/search-memory-selftests.o unittests= /string_view-selftests.o unittests/style-selftests.o unittests/tracepoint-s= elftests.o unittests/tui-selftests.o unittests/ui-file-selftests.o unittest= s/unique_xmalloc_ptr_char.o unittests/unpack-selftests.o unittests/utils-se= lftests.o unittests/vec-utils-selftests.o unittests/xml-utils-selftests.o u= ser-regs.o utils.o valarith.o valops.o valprint.o value.o varobj.o version.= o xml-builtin.o xml-support.o xml-syscall.o xml-tdesc.o init.o \ > ../sim/erc32/libsim.a ../readline/readline/libreadline.a ../opc= odes/libopcodes.a ../libctf/.libs/libctf.a ../bfd/libbfd.a -L./../zlib -lz = ../gdbsupport/libgdbsupport.a ../libiberty/libiberty.a ../libdecnumber/lib= decnumber.a ../libbacktrace/.libs/libbacktrace.a -lncursesw -lm -ldl = ../gnulib/import/libgnu.a -lgmp =20 > /usr/bin/ld: ../sim/erc32/libsim.a(interf.o): in function `sim_open': > /var/cache/git/binutils-gdb/sim/erc32/interf.c:247: undefined reference t= o `fprintf_styled' > collect2: error: ld returned 1 exit status > make[1]: *** [Makefile:2142: gdb] Error 1 > make[1]: Leaving directory '/tmp/sparc/b/gdb' > make: *** [Makefile:13193: all-gdb] Error 2 >=20 >=20 > erc32 has two INIT_DISASSEMBLE_INFO(), of which one doesn't pick the > provided function. Maybe just ordering? Thanks for pointing this out. I pushed the patch below which should fix this problem. Let me know if you still have any problems with the build. Thanks, Andrew --- commit a411a714f31da81e6c57317f1d392e166053dff1 Author: Andrew Burgess Date: Sun Sep 4 17:49:11 2022 +0100 sim/erc32: fix gdb with simulator build =20 In commit: =20 commit 7b01c1cc1d111ba0afa51e60fa9842d3b971e2d1 Date: Mon Apr 4 22:38:04 2022 +0100 =20 sim: fixes for libopcodes styled disassembler =20 changes were made to the simulator source to handle the new libopcodes disassembler styling API. =20 Unfortunately, these changes broke building GDB with the erc32 (sparc) simulator, like this: =20 ../src/configure --target=3Dsparc-linux make all-gdb .... /usr/bin/ld: ../sim/erc32/libsim.a(interf.o): in function `sim_open': /tmp/build/sim/../../src/sim/erc32/interf.c:247: undefined reference = to `fprintf_styled' collect2: error: ld returned 1 exit status =20 The problem is that in commit 7b01c1cc1d11 the fprintf_styled function was added into sis.c. This file is only used when building the 'run' binary, that is, the standalone simulator, and is not included in the libsim.a library. =20 Now, the obvious fix would be to move fprintf_styled into libsim.a, however, that turns out to be tricky. =20 The erc32 simulator currently has two copies of the function run_sim, one in sis.c, and one in interf.c, both of these copies are global. =20 Currently, the 'run' binary links fine, though I suspect this might be pure luck. When I tried moving fprintf_styled into interf.c, I ran into multiple-definition (of run_sim) errors. I suspect that by requiring the linker to pull in fprintf_styled from libsim.a I was changing the order in which symbols were loaded, and the linker was now seeing both copies of run_sim, while currently we only see one copy. =20 The ideal solution of course, would be to merge the two similar, but slightly different copies of run_sim, and just use the one copy. Then we could safely move fprintf_styled into interf.c too, and all would be good. =20 But I don't have time right now to start debugging the erc32 simulator, so I wanted a solution that fixes the build without introducing multiple definition errors. =20 The easiest solution I think is to just have two copies of fprintf_styled, one in sis.c, and one in interf.c. Unlike run_sim, these two copies are both static, so we will not run into multiple definition issues with this function. The functions themselves are not very big, so it's not a huge amount of duplicate code. =20 I am very aware that this is not an ideal solution, and I would welcome anyone who wants to take on fixing the run_sim problem properly, and then cleanup the fprintf_styled duplication. diff --git a/sim/erc32/interf.c b/sim/erc32/interf.c index 78dec6f4b9b..f433b9d55ac 100644 --- a/sim/erc32/interf.c +++ b/sim/erc32/interf.c @@ -156,6 +156,21 @@ run_sim(struct pstate *sregs, uint64_t icount, int dis= ) return TIME_OUT; } =20 +static int +fprintf_styled (void *stream, enum disassembler_style style, +=09=09const char *fmt, ...) +{ + int ret; + FILE *out =3D (FILE *) stream; + va_list args; + + va_start (args, fmt); + ret =3D vfprintf (out, fmt, args); + va_end (args); + + return ret; +} + SIM_DESC sim_open (SIM_OPEN_KIND kind, struct host_callback_struct *callback, =09 struct bfd *abfd, char * const *argv) diff --git a/sim/erc32/sis.c b/sim/erc32/sis.c index 12eb21f15a7..1d3ea139c23 100644 --- a/sim/erc32/sis.c +++ b/sim/erc32/sis.c @@ -138,7 +138,7 @@ run_sim(struct pstate *sregs, uint64_t icount, int dis) return TIME_OUT; } =20 -int +static int fprintf_styled (void *stream, enum disassembler_style style, =09=09const char *fmt, ...) { diff --git a/sim/erc32/sis.h b/sim/erc32/sis.h index 3a276670402..71033137f2c 100644 --- a/sim/erc32/sis.h +++ b/sim/erc32/sis.h @@ -204,8 +204,6 @@ extern void=09init_regs (struct pstate *sregs); /* interf.c */ extern int=09run_sim (struct pstate *sregs, =09=09=09 uint64_t icount, int dis); -extern int fprintf_styled (void *stream, enum disassembler_style styl= e, -=09=09=09=09const char *fmt, ...) ATTRIBUTE_PRINTF (3, 4); =20 /* float.c */ extern int=09get_accex (void);