From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 0595A3857B8D; Sun, 4 Sep 2022 17:03:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0595A3857B8D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1662310985; bh=38imY00MIxCUt2fxAuZSsiq176bEFvUs6zszWu92eB4=; h=From:To:Subject:Date:From; b=hsafI2f5kyTtfgywz/j9ncYZ0XK/6w7OS4iUToibu6/mTvLRV+i3mVGnXEaI8ECEu ChsEsU1c2dhWYbtdZYsX11JqH6Bh9XKVnq3n0ZxwGJRk2Z6KY223tIjRy3F+YH1NnN lNh/UsIZyah5LayVGU40o8lxDu19c/cG0NasqNW8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] sim/erc32: fix gdb with simulator build X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: d236680ae91faba0dbc9d538f0fe8b8869d70595 X-Git-Newrev: a411a714f31da81e6c57317f1d392e166053dff1 Message-Id: <20220904170305.0595A3857B8D@sourceware.org> Date: Sun, 4 Sep 2022 17:03:05 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da411a714f31d= a81e6c57317f1d392e166053dff1 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: --- sim/erc32/interf.c | 15 +++++++++++++++ sim/erc32/sis.c | 2 +- sim/erc32/sis.h | 2 -- 3 files changed, 16 insertions(+), 3 deletions(-) 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, + const 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, 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, const 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 init_regs (struct pstate *sregs); /* interf.c */ extern int run_sim (struct pstate *sregs, uint64_t icount, int dis); -extern int fprintf_styled (void *stream, enum disassembler_style styl= e, - const char *fmt, ...) ATTRIBUTE_PRINTF (3, 4); =20 /* float.c */ extern int get_accex (void);