On 9/5/18 5:52 AM, a...@codesourcery.com wrote: > This patch contains the GCN port of libgcc. I've broken it out just to keep > both parts more manageable. > > We have the usual stuff, plus a "gomp_print" implementation intended to > provide > a means to output text to console without using the full printf. Originally > this was because we did not have a working Newlib port, but now it provides > the > underlying mechanism for printf. It's also much lighter than printf, and > therefore more suitable for debugging offload kernels (for which there is no > debugger, yet). > > In order to work in offload kernels the same function must be present in both > host and GCN toolchains. Therefore it needs to live in libgomp (hence the > name). However, having found it also useful in stand alone testing I have > moved the GCN implementation to libgcc. > > It was also necessary to provide a means to disable EMUTLS. > > 2018-09-05 Andrew Stubbs <a...@codesourcery.com> > Kwok Cheung Yeung <k...@codesourcery.com> > Julian Brown <jul...@codesourcery.com> > Tom de Vries <t...@codesourcery.com> > > libgcc/ > * Makefile.in: Don't add emutls.c when --enable-emutls is "no". > * config.host: Recognize amdgcn*-*-amdhsa. > * config/gcn/crt0.c: New file. > * config/gcn/gomp_print.c: New file. > * config/gcn/lib2-divmod-hi.c: New file. > * config/gcn/lib2-divmod.c: New file. > * config/gcn/lib2-gcn.h: New file. > * config/gcn/reduction.c: New file. > * config/gcn/sfp-machine.h: New file. > * config/gcn/t-amdgcn: New file. > --- > > > 0020-GCN-libgcc.patch > > diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in > index 0c5b264..6f68257 100644 > --- a/libgcc/Makefile.in > +++ b/libgcc/Makefile.in > @@ -429,9 +429,11 @@ LIB2ADD += enable-execute-stack.c > # While emutls.c has nothing to do with EH, it is in LIB2ADDEH* > # instead of LIB2ADD because that's the way to be sure on some targets > # (e.g. *-*-darwin*) only one copy of it is linked. > +ifneq ($(enable_emutls),no) > LIB2ADDEH += $(srcdir)/emutls.c > LIB2ADDEHSTATIC += $(srcdir)/emutls.c > LIB2ADDEHSHARED += $(srcdir)/emutls.c > +endif Why is this needed? Are you just trying to cut out stuff you don't need in the quest for smaller code or does this cause a more direct problem?
> diff --git a/libgcc/config/gcn/crt0.c b/libgcc/config/gcn/crt0.c > new file mode 100644 > index 0000000..f4f367b > --- /dev/null > +++ b/libgcc/config/gcn/crt0.c > @@ -0,0 +1,23 @@ > +/* Copyright (C) 2017 Free Software Foundation, Inc. > + > + This file 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, or (at your option) any > + later version. > + > + This file 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. > + > + Under Section 7 of GPL version 3, you are granted additional > + permissions described in the GCC Runtime Library Exception, version > + 3.1, as published by the Free Software Foundation. > + > + You should have received a copy of the GNU General Public License and > + a copy of the GCC Runtime Library Exception along with this program; > + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see > + <http://www.gnu.org/licenses/>. */ > + > +/* Provide an entry point symbol to silence a linker warning. */ > +void _start() {} This seems wrong. I realize you're trying to quiet a linker warning here, but for the case where you're creating GCN executables (testing?) this should probably be handled by the C-runtime or linker script. > diff --git a/libgcc/config/gcn/gomp_print.c b/libgcc/config/gcn/gomp_print.c > new file mode 100644 > index 0000000..41f50c3 > --- /dev/null > +++ b/libgcc/config/gcn/gomp_print.c [ ... ] Would this be better in libgomp? Oh, you addressed that in the prologue. Feels like libgomp would be better to me, but I can understand the rationale behind wanting it in libgcc. I won't comment on the static sizes since this apparently has to match something already in existence. > + > +void > +gomp_print_string (const char *msg, const char *value) > +{ > + struct printf_data *output = reserve_print_slot (); > + output->type = 2; /* String. */ > + > + strncpy (output->msg, msg, 127); > + output->msg[127] = '\0'; > + strncpy (output->text, value, 127); > + output->text[127] = '\0'; > + > + asm ("" ::: "memory"); > + output->written = 1; > +} I'm not familiar with the GCN memory model, but your asm is really just a barrier for the compiler. Do you need any kind of hardware fencing here? Similarly for other instances. All these functions probably need a little comment on their purpose and arguments. Note some of the divmod stuff recently changed. You may need minor updates as a result of those patches. See: 2018-10-18 Paul Koning <n...@arrl.net> * udivmodsi4.c (__udivmodsi4): Rename to conform to coding standard. * divmod.c: Update references to __udivmodsi4. * udivmod.c: Ditto. * udivhi3.c: New file. * udivmodhi4.c: New file. * config/pdp11/t-pdp11 (LIB2ADD): Add the new files. Jeff