public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* RFC: Building a minimal libgfortran for nvptx
@ 2014-11-04 14:38 Bernd Schmidt
  2014-11-04 15:41 ` Steve Kargl
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Bernd Schmidt @ 2014-11-04 14:38 UTC (permalink / raw)
  To: GCC Patches, gfortran

[-- Attachment #1: Type: text/plain, Size: 1113 bytes --]

The ptx port by its nature is lacking features that are expected on 
"normal" machines, such as alloca and indirect jumps. We have a subset 
of the C library which contains functions that can be implemented on the 
target (excluding things like file I/O other than printf which is a ptx 
builtin).

It would be good to be able to also build as much of libgfortran as 
possible, and the following patch is what I've been using so far. It 
recognizes the target at configure time and restricts the list of 
compiled files, as well as providing a LIBGFOR_MINIMAL define for #ifdef 
tests. There's also a new file minimal.c which contains alternative 
implementations of some functionality (using printf to write error 
messages rather than fprintf and such). Constructors are currently 
unimplemented on ptx and therefore the init function is commented out.

Comments on the approach, do the Fortran maintainers have a preference 
how this should look? The whole thing is good enough to substantially 
reduce the number of failures when trying to run the Fortran testsuites 
on nvptx (although many remain).


Bernd

[-- Attachment #2: gfor-minimal.diff --]
[-- Type: text/x-patch, Size: 28420 bytes --]

Index: libgfortran/Makefile.am
===================================================================
--- libgfortran/Makefile.am.orig
+++ libgfortran/Makefile.am
@@ -77,6 +77,14 @@ AM_CFLAGS += $(SECTION_FLAGS)
 AM_CFLAGS += $(IEEE_FLAGS)
 AM_FCFLAGS += $(IEEE_FLAGS)
 
+if LIBGFOR_MINIMAL
+AM_CFLAGS += -DLIBGFOR_MINIMAL
+endif
+
+if LIBGFOR_MINIMAL
+gfor_io_src= \
+io/size_from_kind.c
+else
 gfor_io_src= \
 io/close.c \
 io/file_pos.c \
@@ -94,6 +102,7 @@ io/unit.c \
 io/unix.c \
 io/write.c \
 io/fbuf.c
+endif
 
 gfor_io_headers= \
 io/io.h \
@@ -101,6 +110,41 @@ io/fbuf.h \
 io/format.h \
 io/unix.h
 
+if LIBGFOR_MINIMAL
+gfor_helper_src= \
+intrinsics/associated.c \
+intrinsics/abort.c \
+intrinsics/args.c \
+intrinsics/bit_intrinsics.c \
+intrinsics/cshift0.c \
+intrinsics/eoshift0.c \
+intrinsics/eoshift2.c \
+intrinsics/erfc_scaled.c \
+intrinsics/extends_type_of.c \
+intrinsics/fnum.c \
+intrinsics/ierrno.c \
+intrinsics/ishftc.c \
+intrinsics/iso_c_generated_procs.c \
+intrinsics/iso_c_binding.c \
+intrinsics/malloc.c \
+intrinsics/mvbits.c \
+intrinsics/move_alloc.c \
+intrinsics/pack_generic.c \
+intrinsics/selected_char_kind.c \
+intrinsics/size.c \
+intrinsics/spread_generic.c \
+intrinsics/string_intrinsics.c \
+intrinsics/rand.c \
+intrinsics/random.c \
+intrinsics/reshape_generic.c \
+intrinsics/reshape_packed.c \
+intrinsics/selected_int_kind.f90 \
+intrinsics/selected_real_kind.f90 \
+intrinsics/transpose_generic.c \
+intrinsics/unpack_generic.c \
+runtime/in_pack_generic.c \
+runtime/in_unpack_generic.c
+else
 gfor_helper_src= \
 intrinsics/associated.c \
 intrinsics/abort.c \
@@ -165,6 +209,7 @@ intrinsics/unlink.c \
 intrinsics/unpack_generic.c \
 runtime/in_pack_generic.c \
 runtime/in_unpack_generic.c
+endif
 
 if IEEE_SUPPORT
 
@@ -181,6 +226,15 @@ gfor_ieee_src=
 
 endif
 
+if LIBGFOR_MINIMAL
+gfor_src= \
+runtime/bounds.c \
+runtime/compile_options.c \
+runtime/memory.c \
+runtime/minimal.c \
+runtime/string.c \
+runtime/select.c
+else
 gfor_src= \
 runtime/backtrace.c \
 runtime/bounds.c \
@@ -195,6 +249,7 @@ runtime/pause.c \
 runtime/stop.c \
 runtime/string.c \
 runtime/select.c
+endif
 
 i_all_c= \
 $(srcdir)/generated/all_l1.c \
Index: libgfortran/Makefile.in
===================================================================
--- libgfortran/Makefile.in.orig
+++ libgfortran/Makefile.in
@@ -54,10 +54,11 @@ POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
 target_triplet = @target@
-@IEEE_SUPPORT_TRUE@am__append_1 = ieee/ieee_helper.c
+@LIBGFOR_MINIMAL_TRUE@am__append_1 = -DLIBGFOR_MINIMAL
+@IEEE_SUPPORT_TRUE@am__append_2 = ieee/ieee_helper.c
 
 # dummy sources for libtool
-@onestep_TRUE@am__append_2 = libgfortran_c.c libgfortran_f.f90
+@onestep_TRUE@am__append_3 = libgfortran_c.c libgfortran_f.f90
 subdir = .
 DIST_COMMON = ChangeLog $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
 	$(top_srcdir)/configure $(am__configure_deps) \
@@ -121,9 +122,13 @@ libcaf_single_la_LIBADD =
 am_libcaf_single_la_OBJECTS = single.lo
 libcaf_single_la_OBJECTS = $(am_libcaf_single_la_OBJECTS)
 libgfortran_la_LIBADD =
-am__objects_1 = backtrace.lo bounds.lo compile_options.lo \
-	convert_char.lo environ.lo error.lo fpu.lo main.lo memory.lo \
-	pause.lo stop.lo string.lo select.lo
+@LIBGFOR_MINIMAL_FALSE@am__objects_1 = backtrace.lo bounds.lo \
+@LIBGFOR_MINIMAL_FALSE@	compile_options.lo convert_char.lo \
+@LIBGFOR_MINIMAL_FALSE@	environ.lo error.lo fpu.lo main.lo \
+@LIBGFOR_MINIMAL_FALSE@	memory.lo pause.lo stop.lo string.lo \
+@LIBGFOR_MINIMAL_FALSE@	select.lo
+@LIBGFOR_MINIMAL_TRUE@am__objects_1 = bounds.lo compile_options.lo \
+@LIBGFOR_MINIMAL_TRUE@	memory.lo minimal.lo string.lo select.lo
 am__objects_2 = all_l1.lo all_l2.lo all_l4.lo all_l8.lo all_l16.lo
 am__objects_3 = any_l1.lo any_l2.lo any_l4.lo any_l8.lo any_l16.lo
 am__objects_4 = count_1_l.lo count_2_l.lo count_4_l.lo count_8_l.lo \
@@ -260,26 +265,54 @@ am__objects_40 = $(am__objects_2) $(am__
 	$(am__objects_32) $(am__objects_33) $(am__objects_34) \
 	$(am__objects_35) $(am__objects_36) $(am__objects_37) \
 	$(am__objects_38) $(am__objects_39)
-am__objects_41 = close.lo file_pos.lo format.lo inquire.lo \
-	intrinsics.lo list_read.lo lock.lo open.lo read.lo \
-	size_from_kind.lo transfer.lo transfer128.lo unit.lo unix.lo \
-	write.lo fbuf.lo
+@LIBGFOR_MINIMAL_FALSE@am__objects_41 = close.lo file_pos.lo format.lo \
+@LIBGFOR_MINIMAL_FALSE@	inquire.lo intrinsics.lo list_read.lo \
+@LIBGFOR_MINIMAL_FALSE@	lock.lo open.lo read.lo \
+@LIBGFOR_MINIMAL_FALSE@	size_from_kind.lo transfer.lo \
+@LIBGFOR_MINIMAL_FALSE@	transfer128.lo unit.lo unix.lo write.lo \
+@LIBGFOR_MINIMAL_FALSE@	fbuf.lo
+@LIBGFOR_MINIMAL_TRUE@am__objects_41 = size_from_kind.lo
 @IEEE_SUPPORT_TRUE@am__objects_42 = ieee_helper.lo
-am__objects_43 = associated.lo abort.lo access.lo args.lo \
-	bit_intrinsics.lo c99_functions.lo chdir.lo chmod.lo clock.lo \
-	cpu_time.lo cshift0.lo ctime.lo date_and_time.lo dtime.lo \
-	env.lo eoshift0.lo eoshift2.lo erfc_scaled.lo etime.lo \
-	execute_command_line.lo exit.lo extends_type_of.lo fnum.lo \
-	gerror.lo getcwd.lo getlog.lo getXid.lo hostnm.lo ierrno.lo \
-	ishftc.lo iso_c_generated_procs.lo iso_c_binding.lo kill.lo \
-	link.lo malloc.lo mvbits.lo move_alloc.lo pack_generic.lo \
-	perror.lo selected_char_kind.lo signal.lo size.lo sleep.lo \
-	spread_generic.lo string_intrinsics.lo system.lo rand.lo \
-	random.lo rename.lo reshape_generic.lo reshape_packed.lo \
-	selected_int_kind.lo selected_real_kind.lo stat.lo symlnk.lo \
-	system_clock.lo time.lo transpose_generic.lo umask.lo \
-	unlink.lo unpack_generic.lo in_pack_generic.lo \
-	in_unpack_generic.lo $(am__objects_42)
+@LIBGFOR_MINIMAL_FALSE@am__objects_43 = associated.lo abort.lo \
+@LIBGFOR_MINIMAL_FALSE@	access.lo args.lo bit_intrinsics.lo \
+@LIBGFOR_MINIMAL_FALSE@	c99_functions.lo chdir.lo chmod.lo \
+@LIBGFOR_MINIMAL_FALSE@	clock.lo cpu_time.lo cshift0.lo \
+@LIBGFOR_MINIMAL_FALSE@	ctime.lo date_and_time.lo dtime.lo \
+@LIBGFOR_MINIMAL_FALSE@	env.lo eoshift0.lo eoshift2.lo \
+@LIBGFOR_MINIMAL_FALSE@	erfc_scaled.lo etime.lo \
+@LIBGFOR_MINIMAL_FALSE@	execute_command_line.lo exit.lo \
+@LIBGFOR_MINIMAL_FALSE@	extends_type_of.lo fnum.lo gerror.lo \
+@LIBGFOR_MINIMAL_FALSE@	getcwd.lo getlog.lo getXid.lo hostnm.lo \
+@LIBGFOR_MINIMAL_FALSE@	ierrno.lo ishftc.lo \
+@LIBGFOR_MINIMAL_FALSE@	iso_c_generated_procs.lo \
+@LIBGFOR_MINIMAL_FALSE@	iso_c_binding.lo kill.lo link.lo \
+@LIBGFOR_MINIMAL_FALSE@	malloc.lo mvbits.lo move_alloc.lo \
+@LIBGFOR_MINIMAL_FALSE@	pack_generic.lo perror.lo \
+@LIBGFOR_MINIMAL_FALSE@	selected_char_kind.lo signal.lo size.lo \
+@LIBGFOR_MINIMAL_FALSE@	sleep.lo spread_generic.lo \
+@LIBGFOR_MINIMAL_FALSE@	string_intrinsics.lo system.lo rand.lo \
+@LIBGFOR_MINIMAL_FALSE@	random.lo rename.lo reshape_generic.lo \
+@LIBGFOR_MINIMAL_FALSE@	reshape_packed.lo selected_int_kind.lo \
+@LIBGFOR_MINIMAL_FALSE@	selected_real_kind.lo stat.lo symlnk.lo \
+@LIBGFOR_MINIMAL_FALSE@	system_clock.lo time.lo \
+@LIBGFOR_MINIMAL_FALSE@	transpose_generic.lo umask.lo unlink.lo \
+@LIBGFOR_MINIMAL_FALSE@	unpack_generic.lo in_pack_generic.lo \
+@LIBGFOR_MINIMAL_FALSE@	in_unpack_generic.lo $(am__objects_42)
+@LIBGFOR_MINIMAL_TRUE@am__objects_43 = associated.lo abort.lo args.lo \
+@LIBGFOR_MINIMAL_TRUE@	bit_intrinsics.lo cshift0.lo eoshift0.lo \
+@LIBGFOR_MINIMAL_TRUE@	eoshift2.lo erfc_scaled.lo \
+@LIBGFOR_MINIMAL_TRUE@	extends_type_of.lo fnum.lo ierrno.lo \
+@LIBGFOR_MINIMAL_TRUE@	ishftc.lo iso_c_generated_procs.lo \
+@LIBGFOR_MINIMAL_TRUE@	iso_c_binding.lo malloc.lo mvbits.lo \
+@LIBGFOR_MINIMAL_TRUE@	move_alloc.lo pack_generic.lo \
+@LIBGFOR_MINIMAL_TRUE@	selected_char_kind.lo size.lo \
+@LIBGFOR_MINIMAL_TRUE@	spread_generic.lo string_intrinsics.lo \
+@LIBGFOR_MINIMAL_TRUE@	rand.lo random.lo reshape_generic.lo \
+@LIBGFOR_MINIMAL_TRUE@	reshape_packed.lo selected_int_kind.lo \
+@LIBGFOR_MINIMAL_TRUE@	selected_real_kind.lo \
+@LIBGFOR_MINIMAL_TRUE@	transpose_generic.lo unpack_generic.lo \
+@LIBGFOR_MINIMAL_TRUE@	in_pack_generic.lo in_unpack_generic.lo \
+@LIBGFOR_MINIMAL_TRUE@	$(am__objects_42)
 @IEEE_SUPPORT_TRUE@am__objects_44 = ieee_arithmetic.lo \
 @IEEE_SUPPORT_TRUE@	ieee_exceptions.lo ieee_features.lo
 am__objects_45 =
@@ -376,7 +409,7 @@ AMTAR = @AMTAR@
 
 # Some targets require additional compiler options for IEEE compatibility.
 AM_CFLAGS = @AM_CFLAGS@ -fcx-fortran-rules $(SECTION_FLAGS) \
-	$(IEEE_FLAGS)
+	$(IEEE_FLAGS) $(am__append_1)
 AM_FCFLAGS = @AM_FCFLAGS@ $(IEEE_FLAGS)
 AR = @AR@
 AS = @AS@
@@ -554,23 +587,26 @@ AM_CPPFLAGS = -iquote$(srcdir)/io -I$(sr
 	      -I$(srcdir)/$(MULTISRCTOP)../libgcc \
 	      -I$(MULTIBUILDTOP)../libgcc
 
-gfor_io_src = \
-io/close.c \
-io/file_pos.c \
-io/format.c \
-io/inquire.c \
-io/intrinsics.c \
-io/list_read.c \
-io/lock.c \
-io/open.c \
-io/read.c \
-io/size_from_kind.c \
-io/transfer.c \
-io/transfer128.c \
-io/unit.c \
-io/unix.c \
-io/write.c \
-io/fbuf.c
+@LIBGFOR_MINIMAL_FALSE@gfor_io_src = \
+@LIBGFOR_MINIMAL_FALSE@io/close.c \
+@LIBGFOR_MINIMAL_FALSE@io/file_pos.c \
+@LIBGFOR_MINIMAL_FALSE@io/format.c \
+@LIBGFOR_MINIMAL_FALSE@io/inquire.c \
+@LIBGFOR_MINIMAL_FALSE@io/intrinsics.c \
+@LIBGFOR_MINIMAL_FALSE@io/list_read.c \
+@LIBGFOR_MINIMAL_FALSE@io/lock.c \
+@LIBGFOR_MINIMAL_FALSE@io/open.c \
+@LIBGFOR_MINIMAL_FALSE@io/read.c \
+@LIBGFOR_MINIMAL_FALSE@io/size_from_kind.c \
+@LIBGFOR_MINIMAL_FALSE@io/transfer.c \
+@LIBGFOR_MINIMAL_FALSE@io/transfer128.c \
+@LIBGFOR_MINIMAL_FALSE@io/unit.c \
+@LIBGFOR_MINIMAL_FALSE@io/unix.c \
+@LIBGFOR_MINIMAL_FALSE@io/write.c \
+@LIBGFOR_MINIMAL_FALSE@io/fbuf.c
+
+@LIBGFOR_MINIMAL_TRUE@gfor_io_src = \
+@LIBGFOR_MINIMAL_TRUE@io/size_from_kind.c
 
 gfor_io_headers = \
 io/io.h \
@@ -578,54 +614,112 @@ io/fbuf.h \
 io/format.h \
 io/unix.h
 
-gfor_helper_src = intrinsics/associated.c intrinsics/abort.c \
-	intrinsics/access.c intrinsics/args.c \
-	intrinsics/bit_intrinsics.c intrinsics/c99_functions.c \
-	intrinsics/chdir.c intrinsics/chmod.c intrinsics/clock.c \
-	intrinsics/cpu_time.c intrinsics/cshift0.c intrinsics/ctime.c \
-	intrinsics/date_and_time.c intrinsics/dtime.c intrinsics/env.c \
-	intrinsics/eoshift0.c intrinsics/eoshift2.c \
-	intrinsics/erfc_scaled.c intrinsics/etime.c \
-	intrinsics/execute_command_line.c intrinsics/exit.c \
-	intrinsics/extends_type_of.c intrinsics/fnum.c \
-	intrinsics/gerror.c intrinsics/getcwd.c intrinsics/getlog.c \
-	intrinsics/getXid.c intrinsics/hostnm.c intrinsics/ierrno.c \
-	intrinsics/ishftc.c intrinsics/iso_c_generated_procs.c \
-	intrinsics/iso_c_binding.c intrinsics/kill.c intrinsics/link.c \
-	intrinsics/malloc.c intrinsics/mvbits.c \
-	intrinsics/move_alloc.c intrinsics/pack_generic.c \
-	intrinsics/perror.c intrinsics/selected_char_kind.c \
-	intrinsics/signal.c intrinsics/size.c intrinsics/sleep.c \
-	intrinsics/spread_generic.c intrinsics/string_intrinsics.c \
-	intrinsics/system.c intrinsics/rand.c intrinsics/random.c \
-	intrinsics/rename.c intrinsics/reshape_generic.c \
-	intrinsics/reshape_packed.c intrinsics/selected_int_kind.f90 \
-	intrinsics/selected_real_kind.f90 intrinsics/stat.c \
-	intrinsics/symlnk.c intrinsics/system_clock.c \
-	intrinsics/time.c intrinsics/transpose_generic.c \
-	intrinsics/umask.c intrinsics/unlink.c \
-	intrinsics/unpack_generic.c runtime/in_pack_generic.c \
-	runtime/in_unpack_generic.c $(am__append_1)
+@LIBGFOR_MINIMAL_FALSE@gfor_helper_src = intrinsics/associated.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/abort.c intrinsics/access.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/args.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/bit_intrinsics.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/c99_functions.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/chdir.c intrinsics/chmod.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/clock.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/cpu_time.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/cshift0.c intrinsics/ctime.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/date_and_time.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/dtime.c intrinsics/env.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/eoshift0.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/eoshift2.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/erfc_scaled.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/etime.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/execute_command_line.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/exit.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/extends_type_of.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/fnum.c intrinsics/gerror.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/getcwd.c intrinsics/getlog.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/getXid.c intrinsics/hostnm.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/ierrno.c intrinsics/ishftc.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/iso_c_generated_procs.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/iso_c_binding.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/kill.c intrinsics/link.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/malloc.c intrinsics/mvbits.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/move_alloc.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/pack_generic.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/perror.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/selected_char_kind.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/signal.c intrinsics/size.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/sleep.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/spread_generic.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/string_intrinsics.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/system.c intrinsics/rand.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/random.c intrinsics/rename.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/reshape_generic.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/reshape_packed.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/selected_int_kind.f90 \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/selected_real_kind.f90 \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/stat.c intrinsics/symlnk.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/system_clock.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/time.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/transpose_generic.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/umask.c intrinsics/unlink.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/unpack_generic.c \
+@LIBGFOR_MINIMAL_FALSE@	runtime/in_pack_generic.c \
+@LIBGFOR_MINIMAL_FALSE@	runtime/in_unpack_generic.c \
+@LIBGFOR_MINIMAL_FALSE@	$(am__append_2)
+@LIBGFOR_MINIMAL_TRUE@gfor_helper_src = intrinsics/associated.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/abort.c intrinsics/args.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/bit_intrinsics.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/cshift0.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/eoshift0.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/eoshift2.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/erfc_scaled.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/extends_type_of.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/fnum.c intrinsics/ierrno.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/ishftc.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/iso_c_generated_procs.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/iso_c_binding.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/malloc.c intrinsics/mvbits.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/move_alloc.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/pack_generic.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/selected_char_kind.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/size.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/spread_generic.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/string_intrinsics.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/rand.c intrinsics/random.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/reshape_generic.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/reshape_packed.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/selected_int_kind.f90 \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/selected_real_kind.f90 \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/transpose_generic.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/unpack_generic.c \
+@LIBGFOR_MINIMAL_TRUE@	runtime/in_pack_generic.c \
+@LIBGFOR_MINIMAL_TRUE@	runtime/in_unpack_generic.c \
+@LIBGFOR_MINIMAL_TRUE@	$(am__append_2)
 @IEEE_SUPPORT_FALSE@gfor_ieee_src = 
 @IEEE_SUPPORT_TRUE@gfor_ieee_src = \
 @IEEE_SUPPORT_TRUE@ieee/ieee_arithmetic.F90 \
 @IEEE_SUPPORT_TRUE@ieee/ieee_exceptions.F90 \
 @IEEE_SUPPORT_TRUE@ieee/ieee_features.F90
 
-gfor_src = \
-runtime/backtrace.c \
-runtime/bounds.c \
-runtime/compile_options.c \
-runtime/convert_char.c \
-runtime/environ.c \
-runtime/error.c \
-runtime/fpu.c \
-runtime/main.c \
-runtime/memory.c \
-runtime/pause.c \
-runtime/stop.c \
-runtime/string.c \
-runtime/select.c
+@LIBGFOR_MINIMAL_FALSE@gfor_src = \
+@LIBGFOR_MINIMAL_FALSE@runtime/backtrace.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/bounds.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/compile_options.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/convert_char.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/environ.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/error.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/fpu.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/main.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/memory.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/pause.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/stop.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/string.c \
+@LIBGFOR_MINIMAL_FALSE@runtime/select.c
+
+@LIBGFOR_MINIMAL_TRUE@gfor_src = \
+@LIBGFOR_MINIMAL_TRUE@runtime/bounds.c \
+@LIBGFOR_MINIMAL_TRUE@runtime/compile_options.c \
+@LIBGFOR_MINIMAL_TRUE@runtime/memory.c \
+@LIBGFOR_MINIMAL_TRUE@runtime/minimal.c \
+@LIBGFOR_MINIMAL_TRUE@runtime/string.c \
+@LIBGFOR_MINIMAL_TRUE@runtime/select.c
 
 i_all_c = \
 $(srcdir)/generated/all_l1.c \
@@ -1255,7 +1349,7 @@ intrinsics/f2c_specifics.F90
 
 BUILT_SOURCES = $(gfor_built_src) $(gfor_built_specific_src) \
 	$(gfor_built_specific2_src) $(gfor_misc_specifics) \
-	$(am__append_2)
+	$(am__append_3)
 prereq_SRC = $(gfor_src) $(gfor_built_src) $(gfor_io_src) \
     $(gfor_helper_src) $(gfor_ieee_src) $(gfor_io_headers) $(gfor_specific_src)
 
@@ -1669,6 +1763,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/maxval_r4.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/maxval_r8.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memory.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minimal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minloc0_16_i1.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minloc0_16_i16.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minloc0_16_i2.Plo@am__quote@
@@ -2463,6 +2558,13 @@ select.lo: runtime/select.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o select.lo `test -f 'runtime/select.c' || echo '$(srcdir)/'`runtime/select.c
 
+minimal.lo: runtime/minimal.c
+@am__fastdepCC_TRUE@	$(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT minimal.lo -MD -MP -MF $(DEPDIR)/minimal.Tpo -c -o minimal.lo `test -f 'runtime/minimal.c' || echo '$(srcdir)/'`runtime/minimal.c
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/minimal.Tpo $(DEPDIR)/minimal.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='runtime/minimal.c' object='minimal.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o minimal.lo `test -f 'runtime/minimal.c' || echo '$(srcdir)/'`runtime/minimal.c
+
 all_l1.lo: $(srcdir)/generated/all_l1.c
 @am__fastdepCC_TRUE@	$(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT all_l1.lo -MD -MP -MF $(DEPDIR)/all_l1.Tpo -c -o all_l1.lo `test -f '$(srcdir)/generated/all_l1.c' || echo '$(srcdir)/'`$(srcdir)/generated/all_l1.c
 @am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/all_l1.Tpo $(DEPDIR)/all_l1.Plo
Index: libgfortran/caf/single.c
===================================================================
--- libgfortran/caf/single.c.orig
+++ libgfortran/caf/single.c
@@ -48,13 +48,14 @@ caf_static_t *caf_static_list = NULL;
 static void
 caf_runtime_error (const char *message, ...)
 {
+#ifndef LIBGFOR_MINIMAL
   va_list ap;
   fprintf (stderr, "Fortran runtime error: ");
   va_start (ap, message);
   vfprintf (stderr, message, ap);
   va_end (ap);
   fprintf (stderr, "\n");
-
+#endif
   /* FIXME: Shutdown the Fortran RTL to flush the buffer.  PR 43849.  */
   exit (EXIT_FAILURE);
 }
Index: libgfortran/configure
===================================================================
--- libgfortran/configure.orig
+++ libgfortran/configure
@@ -641,6 +641,8 @@ RANLIB
 AR
 AS
 SECTION_FLAGS
+LIBGFOR_MINIMAL_FALSE
+LIBGFOR_MINIMAL_TRUE
 LIBGFOR_USE_SYMVER_SUN_FALSE
 LIBGFOR_USE_SYMVER_SUN_TRUE
 LIBGFOR_USE_SYMVER_GNU_FALSE
@@ -5890,6 +5892,15 @@ else
 fi
 
 
+ if test "x${target_cpu}" = xnvptx; then
+  LIBGFOR_MINIMAL_TRUE=
+  LIBGFOR_MINIMAL_FALSE='#'
+else
+  LIBGFOR_MINIMAL_TRUE='#'
+  LIBGFOR_MINIMAL_FALSE=
+fi
+
+
 # Figure out whether the compiler supports "-ffunction-sections -fdata-sections",
 # similarly to how libstdc++ does it
 ac_test_CFLAGS="${CFLAGS+set}"
@@ -12350,7 +12361,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12353 "configure"
+#line 12364 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12456,7 +12467,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12459 "configure"
+#line 12470 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -26799,6 +26810,10 @@ if test -z "${LIBGFOR_USE_SYMVER_SUN_TRU
   as_fn_error "conditional \"LIBGFOR_USE_SYMVER_SUN\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${LIBGFOR_MINIMAL_TRUE}" && test -z "${LIBGFOR_MINIMAL_FALSE}"; then
+  as_fn_error "conditional \"LIBGFOR_MINIMAL\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${LIBGFOR_BUILD_QUAD_TRUE}" && test -z "${LIBGFOR_BUILD_QUAD_FALSE}"; then
   as_fn_error "conditional \"LIBGFOR_BUILD_QUAD\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
Index: libgfortran/configure.ac
===================================================================
--- libgfortran/configure.ac.orig
+++ libgfortran/configure.ac
@@ -189,6 +189,8 @@ AM_CONDITIONAL(LIBGFOR_USE_SYMVER, [test
 AM_CONDITIONAL(LIBGFOR_USE_SYMVER_GNU, [test "x$gfortran_use_symver" = xgnu])
 AM_CONDITIONAL(LIBGFOR_USE_SYMVER_SUN, [test "x$gfortran_use_symver" = xsun])
 
+AM_CONDITIONAL(LIBGFOR_MINIMAL, [test "x${target_cpu}" = xnvptx])
+
 # Figure out whether the compiler supports "-ffunction-sections -fdata-sections",
 # similarly to how libstdc++ does it
 ac_test_CFLAGS="${CFLAGS+set}"
Index: libgfortran/runtime/compile_options.c
===================================================================
--- libgfortran/runtime/compile_options.c.orig
+++ libgfortran/runtime/compile_options.c
@@ -29,7 +29,7 @@ see the files COPYING3 and COPYING.RUNTI
 /* Useful compile-time options will be stored in here.  */
 compile_options_t compile_options;
 
-
+#ifndef LIBGFOR_MINIMAL
 volatile sig_atomic_t fatal_error_in_progress = 0;
 
 
@@ -146,6 +146,7 @@ maybe_find_addr2line (void)
   if (options.backtrace == -1)
     find_addr2line ();
 }
+#endif
 
 /* Set the usual compile-time options.  */
 extern void set_options (int , int []);
@@ -176,6 +177,7 @@ set_options (int num, int options[])
   if (num >= 9)
     compile_options.fpe_summary = options[8];
 
+#ifndef LIBGFOR_MINIMAL
   /* If backtrace is required, we set signal handlers on the POSIX
      2001 signals with core action.  */
   if (compile_options.backtrace)
@@ -212,6 +214,7 @@ set_options (int num, int options[])
 
       maybe_find_addr2line ();
     }
+#endif
 }
 
 
Index: libgfortran/runtime/minimal.c
===================================================================
--- /dev/null
+++ libgfortran/runtime/minimal.c
@@ -0,0 +1,197 @@
+/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
+   Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran runtime library (libgfortran).
+
+Libgfortran 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.
+
+Libgfortran 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/>.  */
+
+#include "libgfortran.h"
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* Stupid function to be sure the constructor is always linked in, even
+   in the case of static linking.  See PR libfortran/22298 for details.  */
+void
+stupid_function_name_for_static_linking (void)
+{
+  return;
+}
+
+options_t options;
+
+/* This will be 0 for little-endian
+   machines and 1 for big-endian machines.  */
+int big_endian = 0;
+
+
+/* Figure out endianness for this machine.  */
+
+static void
+determine_endianness (void)
+{
+  union
+  {
+    GFC_LOGICAL_8 l8;
+    GFC_LOGICAL_4 l4[2];
+  } u;
+
+  u.l8 = 1;
+  if (u.l4[0])
+    big_endian = 0;
+  else if (u.l4[1])
+    big_endian = 1;
+  else
+    runtime_error ("Unable to determine machine endianness");
+}
+
+
+static int argc_save;
+static char **argv_save;
+
+static const char *exe_path;
+
+/* recursion_check()-- It's possible for additional errors to occur
+ * during fatal error processing.  We detect this condition here and
+ * exit with code 4 immediately. */
+
+#define MAGIC 0x20DE8101
+
+static void
+recursion_check (void)
+{
+  static int magic = 0;
+
+  /* Don't even try to print something at this point */
+  if (magic == MAGIC)
+    sys_abort ();
+
+  magic = MAGIC;
+}
+
+#define STRERR_MAXSZ 256
+
+void
+os_error (const char *message)
+{
+  recursion_check ();
+  printf ("Operating system error: ");
+  printf ("%s\n", message);
+  exit (1);
+}
+iexport(os_error);
+
+void
+runtime_error (const char *message, ...)
+{
+  va_list ap;
+
+  recursion_check ();
+  printf ("Fortran runtime error: ");
+  va_start (ap, message);
+  vprintf (message, ap);
+  va_end (ap);
+  printf ("\n");
+  exit (2);
+}
+iexport(runtime_error);
+
+/* void runtime_error_at()-- These are errors associated with a
+ * run time error generated by the front end compiler.  */
+
+void
+runtime_error_at (const char *where, const char *message, ...)
+{
+  va_list ap;
+
+  recursion_check ();
+  printf ("Fortran runtime error: ");
+  va_start (ap, message);
+  vprintf (message, ap);
+  va_end (ap);
+  printf ("\n");
+  exit (2);
+}
+iexport(runtime_error_at);
+
+/* Return the full path of the executable.  */
+char *
+full_exe_path (void)
+{
+  return (char *) exe_path;
+}
+
+
+/* Set the saved values of the command line arguments.  */
+
+void
+set_args (int argc, char **argv)
+{
+  argc_save = argc;
+  argv_save = argv;
+  exe_path = argv[0];
+}
+iexport(set_args);
+
+
+/* Retrieve the saved values of the command line arguments.  */
+
+void
+get_args (int *argc, char ***argv)
+{
+  *argc = argc_save;
+  *argv = argv_save;
+}
+
+#if 0
+/* Initialize the runtime library.  */
+
+static void /* __attribute__((constructor)) */
+init (void)
+{
+  /* Figure out the machine endianness.  */
+  determine_endianness ();
+
+  /* Must be first */
+  init_variables ();
+
+  set_fpu ();
+  init_compile_options ();
+
+  random_seed_i4 (NULL, NULL, NULL);
+}
+
+#endif
+
+/* sys_abort()-- Terminate the program showing backtrace and dumping
+   core.  */
+
+void
+sys_abort (void)
+{
+  printf ("Abort called.\n");
+  abort();
+}

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 14:38 RFC: Building a minimal libgfortran for nvptx Bernd Schmidt
@ 2014-11-04 15:41 ` Steve Kargl
  2014-11-04 15:58   ` Bernd Schmidt
  2014-11-04 16:12   ` Jakub Jelinek
  2014-11-04 15:59 ` FX
  2014-11-13 22:14 ` Tobias Burnus
  2 siblings, 2 replies; 21+ messages in thread
From: Steve Kargl @ 2014-11-04 15:41 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: GCC Patches, gfortran

On Tue, Nov 04, 2014 at 03:34:43PM +0100, Bernd Schmidt wrote:
> The ptx port by its nature is lacking features that are expected on 
> "normal" machines, such as alloca and indirect jumps. We have a subset 
> of the C library which contains functions that can be implemented on the 
> target (excluding things like file I/O other than printf which is a ptx 
> builtin).
> 
> It would be good to be able to also build as much of libgfortran as 
> possible, and the following patch is what I've been using so far. It 
> recognizes the target at configure time and restricts the list of 
> compiled files, as well as providing a LIBGFOR_MINIMAL define for #ifdef 
> tests. There's also a new file minimal.c which contains alternative 
> implementations of some functionality (using printf to write error 
> messages rather than fprintf and such). Constructors are currently 
> unimplemented on ptx and therefore the init function is commented out.
> 
> Comments on the approach, do the Fortran maintainers have a preference 
> how this should look? The whole thing is good enough to substantially 
> reduce the number of failures when trying to run the Fortran testsuites 
> on nvptx (although many remain).
> 

It is unclear to me from reading the diff whether this patch 
cause gfortran on ptx to knowingly violate the fortran standard.
If the answer is "yes, this patch causes gfortran on ptx to
violate the standard", then the patch is IMHO unacceptable.

-- 
steve

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 15:41 ` Steve Kargl
@ 2014-11-04 15:58   ` Bernd Schmidt
  2014-11-04 17:08     ` Steve Kargl
  2014-11-04 18:19     ` Jeff Law
  2014-11-04 16:12   ` Jakub Jelinek
  1 sibling, 2 replies; 21+ messages in thread
From: Bernd Schmidt @ 2014-11-04 15:58 UTC (permalink / raw)
  To: Steve Kargl; +Cc: GCC Patches, gfortran

On 11/04/2014 04:41 PM, Steve Kargl wrote:
> It is unclear to me from reading the diff whether this patch
> cause gfortran on ptx to knowingly violate the fortran standard.
> If the answer is "yes, this patch causes gfortran on ptx to
> violate the standard", then the patch is IMHO unacceptable.

I don't have the Fortran standard, but I assume that missing pieces in 
the library would be a violation. However, the alternative is no Fortran 
(library) support at all, which doesn't seem like an improvement. The 
target simply does not allow full language support, even for something 
like C.

Note that the intention is not to support Fortran (or any other 
language) directly targetting ptx code. The only way it's supposed to be 
used is as an accelerator for OpenACC offloading.


Bernd

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 14:38 RFC: Building a minimal libgfortran for nvptx Bernd Schmidt
  2014-11-04 15:41 ` Steve Kargl
@ 2014-11-04 15:59 ` FX
  2014-11-04 16:10   ` Bernd Schmidt
  2014-11-13 22:14 ` Tobias Burnus
  2 siblings, 1 reply; 21+ messages in thread
From: FX @ 2014-11-04 15:59 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: GCC Patches, gfortran

> Comments on the approach, do the Fortran maintainers have a preference how this should look? The whole thing is good enough to substantially reduce the number of failures when trying to run the Fortran testsuites on nvptx (although many remain).

I’m afraid I don’t really see the point. Maybe I’ll say it differently that Steve has: what would be the state of Fortran on such platform, and would it have users? It looks that, at the very least, your target wouldn’t be able to do any I/O.

Unless we have a good reason to think there will be users, because the state of support will be good, I don’t see that we should add to the library maintainance burden by special-casing targets.

Also: if other targets come along that have this need, how does your strategy scale up?

Thanks,
FX

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 15:59 ` FX
@ 2014-11-04 16:10   ` Bernd Schmidt
  0 siblings, 0 replies; 21+ messages in thread
From: Bernd Schmidt @ 2014-11-04 16:10 UTC (permalink / raw)
  To: FX; +Cc: GCC Patches, gfortran

On 11/04/2014 04:59 PM, FX wrote:
>> Comments on the approach, do the Fortran maintainers have a
>> preference how this should look? The whole thing is good enough to
>> substantially reduce the number of failures when trying to run the
>> Fortran testsuites on nvptx (although many remain).
>
> IÂ’m afraid I donÂ’t really see the point. Maybe IÂ’ll say it
> differently that Steve has: what would be the state of Fortran on
> such platform, and would it have users? It looks that, at the very
> least, your target wouldnÂ’t be able to do any I/O.

It would be used through OpenACC - and that I do believe that does have 
Fortran users, with other compilers. We can make Fortran OpenACC work 
for simple testcases without any runtime library, but IMO it would be 
better to go as far as possible in supporting whatever can be made to 
work. I/O is the major piece that is missing, but you'd expect that to 
be done on the host rather than on the accelerator.


Bernd

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 15:41 ` Steve Kargl
  2014-11-04 15:58   ` Bernd Schmidt
@ 2014-11-04 16:12   ` Jakub Jelinek
  2014-11-04 16:15     ` FX
  2014-11-04 17:21     ` Jeff Law
  1 sibling, 2 replies; 21+ messages in thread
From: Jakub Jelinek @ 2014-11-04 16:12 UTC (permalink / raw)
  To: Steve Kargl; +Cc: Bernd Schmidt, GCC Patches, gfortran

On Tue, Nov 04, 2014 at 07:41:42AM -0800, Steve Kargl wrote:
> On Tue, Nov 04, 2014 at 03:34:43PM +0100, Bernd Schmidt wrote:
> > The ptx port by its nature is lacking features that are expected on 
> > "normal" machines, such as alloca and indirect jumps. We have a subset 
> > of the C library which contains functions that can be implemented on the 
> > target (excluding things like file I/O other than printf which is a ptx 
> > builtin).
> > 
> > It would be good to be able to also build as much of libgfortran as 
> > possible, and the following patch is what I've been using so far. It 
> > recognizes the target at configure time and restricts the list of 
> > compiled files, as well as providing a LIBGFOR_MINIMAL define for #ifdef 
> > tests. There's also a new file minimal.c which contains alternative 
> > implementations of some functionality (using printf to write error 
> > messages rather than fprintf and such). Constructors are currently 
> > unimplemented on ptx and therefore the init function is commented out.
> > 
> > Comments on the approach, do the Fortran maintainers have a preference 
> > how this should look? The whole thing is good enough to substantially 
> > reduce the number of failures when trying to run the Fortran testsuites 
> > on nvptx (although many remain).
> > 
> 
> It is unclear to me from reading the diff whether this patch 
> cause gfortran on ptx to knowingly violate the fortran standard.
> If the answer is "yes, this patch causes gfortran on ptx to
> violate the standard", then the patch is IMHO unacceptable.

The point is, if the target can implement just a subset of the Fortran (or
C or C++) standards, then ideally if you use anything that is not supported
would just cause always host fallback, the code will still work, but will
not be offloaded.  So even supporting a subset of the standard is
worthwhile, usually one will just offload the most performance critical
parts of his code.

	Jakub

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 16:12   ` Jakub Jelinek
@ 2014-11-04 16:15     ` FX
  2014-11-04 16:19       ` Jakub Jelinek
  2014-11-04 17:21     ` Jeff Law
  1 sibling, 1 reply; 21+ messages in thread
From: FX @ 2014-11-04 16:15 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Steve Kargl, Bernd Schmidt, GCC Patches, gfortran

> The point is, if the target can implement just a subset of the Fortran (or
> C or C++) standards, then ideally if you use anything that is not supported
> would just cause always host fallback, the code will still work, but will
> not be offloaded.  So even supporting a subset of the standard is
> worthwhile, usually one will just offload the most performance critical
> parts of his code.

Do we have the architecture for that in place in GCC in general, and in the Fortran front-end in particular? I’d be interested to see how it works…

FX

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 16:15     ` FX
@ 2014-11-04 16:19       ` Jakub Jelinek
  2014-11-04 17:11         ` FX
  0 siblings, 1 reply; 21+ messages in thread
From: Jakub Jelinek @ 2014-11-04 16:19 UTC (permalink / raw)
  To: FX; +Cc: Steve Kargl, Bernd Schmidt, GCC Patches, gfortran

On Tue, Nov 04, 2014 at 05:15:52PM +0100, FX wrote:
> > The point is, if the target can implement just a subset of the Fortran (or
> > C or C++) standards, then ideally if you use anything that is not supported
> > would just cause always host fallback, the code will still work, but will
> > not be offloaded.  So even supporting a subset of the standard is
> > worthwhile, usually one will just offload the most performance critical
> > parts of his code.
> 
> Do we have the architecture for that in place in GCC in general, and in
> the Fortran front-end in particular?  I’d be interested to see how it
> works…

See https://gcc.gnu.org/wiki/Offloading and kyukhin/gomp4-offload and
branches/gomp-4_0-branch branches.  Both are in the process of being merged
into trunk these days.

	Jakub

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 15:58   ` Bernd Schmidt
@ 2014-11-04 17:08     ` Steve Kargl
  2014-11-04 18:19     ` Jeff Law
  1 sibling, 0 replies; 21+ messages in thread
From: Steve Kargl @ 2014-11-04 17:08 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: GCC Patches, gfortran

On Tue, Nov 04, 2014 at 04:54:54PM +0100, Bernd Schmidt wrote:
> On 11/04/2014 04:41 PM, Steve Kargl wrote:
> > It is unclear to me from reading the diff whether this patch
> > cause gfortran on ptx to knowingly violate the fortran standard.
> > If the answer is "yes, this patch causes gfortran on ptx to
> > violate the standard", then the patch is IMHO unacceptable.
> 
> I don't have the Fortran standard, but I assume that missing pieces in 
> the library would be a violation. However, the alternative is no Fortran 
> (library) support at all, which doesn't seem like an improvement. The 
> target simply does not allow full language support, even for something 
> like C.
> 
> Note that the intention is not to support Fortran (or any other 
> language) directly targetting ptx code. The only way it's supposed to be 
> used is as an accelerator for OpenACC offloading.
> 

I see.  I get nervous when a patch appears that throws away
a part of the runtime library.  There are typically unintended
consequences, which then becomes a support issue.

-- 
Steve

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 16:19       ` Jakub Jelinek
@ 2014-11-04 17:11         ` FX
  0 siblings, 0 replies; 21+ messages in thread
From: FX @ 2014-11-04 17:11 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Steve Kargl, Bernd Schmidt, GCC Patches, gfortran

> See https://gcc.gnu.org/wiki/Offloading and kyukhin/gomp4-offload and
> branches/gomp-4_0-branch branches.  Both are in the process of being merged
> into trunk these days.

Thanks for the link, I’ll look into it.
I suppose then it makes sense to provide partial libgfortran support, assuming someone is volunteering to make offloading work nicely for Fortran code and maintain it.

FX

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 16:12   ` Jakub Jelinek
  2014-11-04 16:15     ` FX
@ 2014-11-04 17:21     ` Jeff Law
  2014-11-04 17:38       ` Steve Kargl
  2014-11-04 18:44       ` N.M. Maclaren
  1 sibling, 2 replies; 21+ messages in thread
From: Jeff Law @ 2014-11-04 17:21 UTC (permalink / raw)
  To: Jakub Jelinek, Steve Kargl; +Cc: Bernd Schmidt, GCC Patches, gfortran

On 11/04/14 09:11, Jakub Jelinek wrote:
> On Tue, Nov 04, 2014 at 07:41:42AM -0800, Steve Kargl wrote:
>> On Tue, Nov 04, 2014 at 03:34:43PM +0100, Bernd Schmidt wrote:
>>> The ptx port by its nature is lacking features that are expected on
>>> "normal" machines, such as alloca and indirect jumps. We have a subset
>>> of the C library which contains functions that can be implemented on the
>>> target (excluding things like file I/O other than printf which is a ptx
>>> builtin).
>>>
>>> It would be good to be able to also build as much of libgfortran as
>>> possible, and the following patch is what I've been using so far. It
>>> recognizes the target at configure time and restricts the list of
>>> compiled files, as well as providing a LIBGFOR_MINIMAL define for #ifdef
>>> tests. There's also a new file minimal.c which contains alternative
>>> implementations of some functionality (using printf to write error
>>> messages rather than fprintf and such). Constructors are currently
>>> unimplemented on ptx and therefore the init function is commented out.
>>>
>>> Comments on the approach, do the Fortran maintainers have a preference
>>> how this should look? The whole thing is good enough to substantially
>>> reduce the number of failures when trying to run the Fortran testsuites
>>> on nvptx (although many remain).
>>>
>>
>> It is unclear to me from reading the diff whether this patch
>> cause gfortran on ptx to knowingly violate the fortran standard.
>> If the answer is "yes, this patch causes gfortran on ptx to
>> violate the standard", then the patch is IMHO unacceptable.
>
> The point is, if the target can implement just a subset of the Fortran (or
> C or C++) standards, then ideally if you use anything that is not supported
> would just cause always host fallback, the code will still work, but will
> not be offloaded.  So even supporting a subset of the standard is
> worthwhile, usually one will just offload the most performance critical
> parts of his code.
Also note there's a reasonable chance that the GPUs will continue to 
evolve and will be able to support more of the standard language 
features.  Not sure if they'll ever do the IO side of Fortran, but they 
could always surprise us.

jeff

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 17:21     ` Jeff Law
@ 2014-11-04 17:38       ` Steve Kargl
  2014-11-04 18:44       ` N.M. Maclaren
  1 sibling, 0 replies; 21+ messages in thread
From: Steve Kargl @ 2014-11-04 17:38 UTC (permalink / raw)
  To: Jeff Law; +Cc: Jakub Jelinek, Bernd Schmidt, GCC Patches, gfortran

On Tue, Nov 04, 2014 at 10:20:53AM -0700, Jeff Law wrote:
> On 11/04/14 09:11, Jakub Jelinek wrote:
> > On Tue, Nov 04, 2014 at 07:41:42AM -0800, Steve Kargl wrote:
> >> On Tue, Nov 04, 2014 at 03:34:43PM +0100, Bernd Schmidt wrote:
> >>> The ptx port by its nature is lacking features that are expected on
> >>> "normal" machines, such as alloca and indirect jumps. We have a subset
> >>> of the C library which contains functions that can be implemented on the
> >>> target (excluding things like file I/O other than printf which is a ptx
> >>> builtin).
> >>>
> >>> It would be good to be able to also build as much of libgfortran as
> >>> possible, and the following patch is what I've been using so far. It
> >>> recognizes the target at configure time and restricts the list of
> >>> compiled files, as well as providing a LIBGFOR_MINIMAL define for #ifdef
> >>> tests. There's also a new file minimal.c which contains alternative
> >>> implementations of some functionality (using printf to write error
> >>> messages rather than fprintf and such). Constructors are currently
> >>> unimplemented on ptx and therefore the init function is commented out.
> >>>
> >>> Comments on the approach, do the Fortran maintainers have a preference
> >>> how this should look? The whole thing is good enough to substantially
> >>> reduce the number of failures when trying to run the Fortran testsuites
> >>> on nvptx (although many remain).
> >>>
> >>
> >> It is unclear to me from reading the diff whether this patch
> >> cause gfortran on ptx to knowingly violate the fortran standard.
> >> If the answer is "yes, this patch causes gfortran on ptx to
> >> violate the standard", then the patch is IMHO unacceptable.
> >
> > The point is, if the target can implement just a subset of the Fortran (or
> > C or C++) standards, then ideally if you use anything that is not supported
> > would just cause always host fallback, the code will still work, but will
> > not be offloaded.  So even supporting a subset of the standard is
> > worthwhile, usually one will just offload the most performance critical
> > parts of his code.
> Also note there's a reasonable chance that the GPUs will continue to 
> evolve and will be able to support more of the standard language 
> features.  Not sure if they'll ever do the IO side of Fortran, but they 
> could always surprise us.
> 

Thanks for the explanation.  Certainly mapping Fortran's array syntax
and many of the intrinsic subprograms to an accelerator may provide a
nice speed improvement.  It wasn't clear to me from Bernd original message
that the patch was intended for OpenACC offloading.  I was assuming
that ptx was a new cpu architecture, which had limited capabilites.

-- 
Steve

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 15:58   ` Bernd Schmidt
  2014-11-04 17:08     ` Steve Kargl
@ 2014-11-04 18:19     ` Jeff Law
  1 sibling, 0 replies; 21+ messages in thread
From: Jeff Law @ 2014-11-04 18:19 UTC (permalink / raw)
  To: Bernd Schmidt, Steve Kargl; +Cc: GCC Patches, gfortran

On 11/04/14 08:54, Bernd Schmidt wrote:
> Note that the intention is not to support Fortran (or any other
> language) directly targetting ptx code. The only way it's supposed to be
> used is as an accelerator for OpenACC offloading.
Right.  To reiterate for everyone, offloading is the goal of the nvptx 
port.  Normal C, C++, Fortran code really isn't interesting, though the 
direction the hardware is going should allow more and more C, C++ & 
Fortran code to be used as-is on the GPU.

Bernd has done a fair amount of work to allow normal-ish C, C++ & 
Fortran code to run, that's really been to allow running GCC's testsuite 
to shake out the first level bugs in the ptx support.

Jeff

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 17:21     ` Jeff Law
  2014-11-04 17:38       ` Steve Kargl
@ 2014-11-04 18:44       ` N.M. Maclaren
  1 sibling, 0 replies; 21+ messages in thread
From: N.M. Maclaren @ 2014-11-04 18:44 UTC (permalink / raw)
  To: Jeff Law; +Cc: Jakub Jelinek, Steve Kargl, Bernd Schmidt, GCC Patches, gfortran

On Nov 4 2014, Jeff Law wrote:
>On 11/04/14 09:11, Jakub Jelinek wrote:
>>
>> The point is, if the target can implement just a subset of the Fortran 
>> (or C or C++) standards, then ideally if you use anything that is not 
>> supported would just cause always host fallback, the code will still 
>> work, but will not be offloaded. So even supporting a subset of the 
>> standard is worthwhile, usually one will just offload the most 
>> performance critical parts of his code.

As I see it, this isn't a free-standing compilation environment, but a
component of one for heterogeneous architectures.  There are similar
issues for some embedded systems, in several languages.  That doesn't
fit well with the current build model, unfortunately :-(

>Also note there's a reasonable chance that the GPUs will continue to 
>evolve and will be able to support more of the standard language 
>features.  Not sure if they'll ever do the IO side of Fortran, but they 
>could always surprise us.

I am almost certain that the current situation is going to change
significantly, probably by 2020, but there is as yet no indication of
how.  And it wouldn't be entirely reasonable to say nothing should be
done for this sort of use until the situation becomes clear.


Regards,
Nick Maclaren.

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-04 14:38 RFC: Building a minimal libgfortran for nvptx Bernd Schmidt
  2014-11-04 15:41 ` Steve Kargl
  2014-11-04 15:59 ` FX
@ 2014-11-13 22:14 ` Tobias Burnus
  2014-11-14 17:21   ` Bernd Schmidt
  2 siblings, 1 reply; 21+ messages in thread
From: Tobias Burnus @ 2014-11-13 22:14 UTC (permalink / raw)
  To: Bernd Schmidt, GCC Patches, gfortran

Hi all,

since everyone seems to agree that it makes in principle sense to have a 
reduce libgfortran (even though a full one is nicer, if the system 
permits), let's look at the patch itself ;-)

Bernd Schmidt wrote:
> The ptx port by its nature is lacking features that are expected on 
> "normal" machines, such as alloca and indirect jumps. We have a subset 
> of the C library which contains functions that can be implemented on 
> the target (excluding things like file I/O other than printf which is 
> a ptx builtin).
>
> It would be good to be able to also build as much of libgfortran as 
> possible, and the following patch is what I've been using so far. It 
> recognizes the target at configure time and restricts the list of 
> compiled files, as well as providing a LIBGFOR_MINIMAL define for 
> #ifdef tests. There's also a new file minimal.c which contains 
> alternative implementations of some functionality (using printf to 
> write error messages rather than fprintf and such). Constructors are 
> currently unimplemented on ptx and therefore the init function is 
> commented out.

Does printf work? I thought I/O is not supported? Or does it just accept 
it for linking and drop it? I think Janne's patch has already dealt with 
the issue of stack allocation.

What I dislike a bit about the feature is that it is not clear what 
features will be supported for LIBGFOR_MINIMAL. Maybe configure.ac would 
be a good place to describe which features are included there (e.g. no 
I/O but "printf" etc.) and which aren't. That will make it easier to see 
what has to be modifed if one will add another differently bare system 
later on.

+#if 0
+/* Initialize the runtime library.  */

#if 0'ed code shouldn't be in the patch.


+@LIBGFOR_MINIMAL_FALSE@gfor_helper_src = intrinsics/associated.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/abort.c intrinsics/access.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/args.c \
+@LIBGFOR_MINIMAL_FALSE@	intrinsics/bit_intrinsics.c \
...
+@LIBGFOR_MINIMAL_TRUE@gfor_helper_src = intrinsics/associated.c \
+@LIBGFOR_MINIMAL_TRUE@	intrinsics/abort.c intrinsics/args.c \
...

Can't one write this differently, avoiding having most lines repeated 
and only a few missing from the second set? I am not an automake expert, 
but can't one simply split this into different make variables - one set 
which is in both and one which is not in minimal?

Otherwise, the RFC looks good to me.

Tobias

Tobias

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-13 22:14 ` Tobias Burnus
@ 2014-11-14 17:21   ` Bernd Schmidt
  2014-11-14 21:39     ` Tobias Burnus
  2015-03-11 21:48     ` Thomas Schwinge
  0 siblings, 2 replies; 21+ messages in thread
From: Bernd Schmidt @ 2014-11-14 17:21 UTC (permalink / raw)
  To: Tobias Burnus, GCC Patches, gfortran

[-- Attachment #1: Type: text/plain, Size: 1734 bytes --]

Hi Tobias,

> Does printf work? I thought I/O is not supported? Or does it just accept
> it for linking and drop it? I think Janne's patch has already dealt with
> the issue of stack allocation.

printf (or more accurately vprintf) is supported by ptx as a magic 
builtin function. We have a printf wrapper around vprintf in our newlib. 
What was Janne's patch?

> What I dislike a bit about the feature is that it is not clear what
> features will be supported for LIBGFOR_MINIMAL. Maybe configure.ac would
> be a good place to describe which features are included there (e.g. no
> I/O but "printf" etc.) and which aren't. That will make it easier to see
> what has to be modifed if one will add another differently bare system
> later on.

My view is that it makes no sense to generalize this at the moment when 
it is unknown what another target that uses this would look like. The 
time to revisit this is when there is another target.

> +#if 0
> +/* Initialize the runtime library.  */
>
> #if 0'ed code shouldn't be in the patch.

Ok, removed - I'll put it back if we ever support constructors.

> +@LIBGFOR_MINIMAL_FALSE@gfor_helper_src = intrinsics/associated.c \
> +@LIBGFOR_MINIMAL_FALSE@    intrinsics/abort.c intrinsics/access.c \
> +@LIBGFOR_MINIMAL_FALSE@    intrinsics/args.c \
> +@LIBGFOR_MINIMAL_FALSE@    intrinsics/bit_intrinsics.c \
> ...
> +@LIBGFOR_MINIMAL_TRUE@gfor_helper_src = intrinsics/associated.c \
> +@LIBGFOR_MINIMAL_TRUE@    intrinsics/abort.c intrinsics/args.c \
> ...
>
> Can't one write this differently, avoiding having most lines repeated
> and only a few missing from the second set?

Modified. New patch below, how does this look? Regenerated files not 
included. Testing in progress.


Bernd


[-- Attachment #2: gfor-minimal-v2.diff --]
[-- Type: text/x-patch, Size: 10551 bytes --]

	* Makefile.am (AM_CFLAGS): Add -DLIBGFOR_MINIMAL if LIBGFOR_MINIMAL.
	(gfor_io_src, gfor_heper_src, gfor_src): Split into minimal and
	always included sources.
	* Makefile.in: Regenerate.
	* configure.ac (LIBGFOR_MINIMAL): New AM_CONDITIONAL.
	* configure: Regenerate.
	* caf/single.c (caf_runtime_error): Don't print messages if
	LIBGFOR_MINIMAL.
	* runtime/compile_options.c (fatal_error_in_progress,
	show_signal, backtrace_handler, maybe_find_addr2line): Guard with
	!defined LIBGFOR_MINIMAL.
	(set_options): Likewise for the backtrace code.
	* runtime/minimal.c: New file.

diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index a058a01..31eb986 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -77,7 +77,16 @@ AM_CFLAGS += $(SECTION_FLAGS)
 AM_CFLAGS += $(IEEE_FLAGS)
 AM_FCFLAGS += $(IEEE_FLAGS)
 
+if LIBGFOR_MINIMAL
+AM_CFLAGS += -DLIBGFOR_MINIMAL
+endif
+
 gfor_io_src= \
+io/size_from_kind.c
+
+if !LIBGFOR_MINIMAL
+
+gfor_io_src+= \
 io/close.c \
 io/file_pos.c \
 io/format.c \
@@ -87,7 +96,6 @@ io/list_read.c \
 io/lock.c \
 io/open.c \
 io/read.c \
-io/size_from_kind.c \
 io/transfer.c \
 io/transfer128.c \
 io/unit.c \
@@ -95,6 +103,8 @@ io/unix.c \
 io/write.c \
 io/fbuf.c
 
+endif
+
 gfor_io_headers= \
 io/io.h \
 io/fbuf.h \
@@ -104,67 +114,73 @@ io/unix.h
 gfor_helper_src= \
 intrinsics/associated.c \
 intrinsics/abort.c \
-intrinsics/access.c \
 intrinsics/args.c \
 intrinsics/bit_intrinsics.c \
-intrinsics/c99_functions.c \
-intrinsics/chdir.c \
-intrinsics/chmod.c \
-intrinsics/clock.c \
-intrinsics/cpu_time.c \
 intrinsics/cshift0.c \
-intrinsics/ctime.c \
-intrinsics/date_and_time.c \
-intrinsics/dtime.c \
-intrinsics/env.c \
 intrinsics/eoshift0.c \
 intrinsics/eoshift2.c \
 intrinsics/erfc_scaled.c \
-intrinsics/etime.c \
-intrinsics/execute_command_line.c \
-intrinsics/exit.c \
 intrinsics/extends_type_of.c \
 intrinsics/fnum.c \
-intrinsics/gerror.c \
-intrinsics/getcwd.c \
-intrinsics/getlog.c \
-intrinsics/getXid.c \
-intrinsics/hostnm.c \
 intrinsics/ierrno.c \
 intrinsics/ishftc.c \
 intrinsics/iso_c_generated_procs.c \
 intrinsics/iso_c_binding.c \
-intrinsics/kill.c \
-intrinsics/link.c \
 intrinsics/malloc.c \
 intrinsics/mvbits.c \
 intrinsics/move_alloc.c \
 intrinsics/pack_generic.c \
-intrinsics/perror.c \
 intrinsics/selected_char_kind.c \
-intrinsics/signal.c \
 intrinsics/size.c \
-intrinsics/sleep.c \
 intrinsics/spread_generic.c \
 intrinsics/string_intrinsics.c \
-intrinsics/system.c \
 intrinsics/rand.c \
 intrinsics/random.c \
-intrinsics/rename.c \
 intrinsics/reshape_generic.c \
 intrinsics/reshape_packed.c \
 intrinsics/selected_int_kind.f90 \
 intrinsics/selected_real_kind.f90 \
+intrinsics/transpose_generic.c \
+intrinsics/unpack_generic.c \
+runtime/in_pack_generic.c \
+runtime/in_unpack_generic.c
+
+if !LIBGFOR_MINIMAL
+
+gfor_helper_src+= \
+intrinsics/access.c \
+intrinsics/c99_functions.c \
+intrinsics/chdir.c \
+intrinsics/chmod.c \
+intrinsics/clock.c \
+intrinsics/cpu_time.c \
+intrinsics/ctime.c \
+intrinsics/date_and_time.c \
+intrinsics/dtime.c \
+intrinsics/env.c \
+intrinsics/etime.c \
+intrinsics/execute_command_line.c \
+intrinsics/exit.c \
+intrinsics/gerror.c \
+intrinsics/getcwd.c \
+intrinsics/getlog.c \
+intrinsics/getXid.c \
+intrinsics/hostnm.c \
+intrinsics/kill.c \
+intrinsics/link.c \
+intrinsics/perror.c \
+intrinsics/signal.c \
+intrinsics/sleep.c \
+intrinsics/system.c \
+intrinsics/rename.c \
 intrinsics/stat.c \
 intrinsics/symlnk.c \
 intrinsics/system_clock.c \
 intrinsics/time.c \
-intrinsics/transpose_generic.c \
 intrinsics/umask.c \
-intrinsics/unlink.c \
-intrinsics/unpack_generic.c \
-runtime/in_pack_generic.c \
-runtime/in_unpack_generic.c
+intrinsics/unlink.c
+
+endif
 
 if IEEE_SUPPORT
 
@@ -182,19 +198,29 @@ gfor_ieee_src=
 endif
 
 gfor_src= \
-runtime/backtrace.c \
 runtime/bounds.c \
 runtime/compile_options.c \
+runtime/memory.c \
+runtime/string.c \
+runtime/select.c
+
+if LIBGFOR_MINIMAL
+
+gfor_src+= runtime/minimal.c
+
+else
+
+gfor_src+= \
+runtime/backtrace.c \
 runtime/convert_char.c \
 runtime/environ.c \
 runtime/error.c \
 runtime/fpu.c \
 runtime/main.c \
-runtime/memory.c \
 runtime/pause.c \
-runtime/stop.c \
-runtime/string.c \
-runtime/select.c
+runtime/stop.c
+
+endif
 
 i_all_c= \
 $(srcdir)/generated/all_l1.c \
diff --git a/libgfortran/caf/single.c b/libgfortran/caf/single.c
index e264fc5..632d172 100644
--- a/libgfortran/caf/single.c
+++ b/libgfortran/caf/single.c
@@ -48,13 +48,14 @@ caf_static_t *caf_static_list = NULL;
 static void
 caf_runtime_error (const char *message, ...)
 {
+#ifndef LIBGFOR_MINIMAL
   va_list ap;
   fprintf (stderr, "Fortran runtime error: ");
   va_start (ap, message);
   vfprintf (stderr, message, ap);
   va_end (ap);
   fprintf (stderr, "\n");
-
+#endif
   /* FIXME: Shutdown the Fortran RTL to flush the buffer.  PR 43849.  */
   exit (EXIT_FAILURE);
 }
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index ada74e3..8ffdd2f 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -189,6 +189,8 @@ AM_CONDITIONAL(LIBGFOR_USE_SYMVER, [test "x$gfortran_use_symver" != xno])
 AM_CONDITIONAL(LIBGFOR_USE_SYMVER_GNU, [test "x$gfortran_use_symver" = xgnu])
 AM_CONDITIONAL(LIBGFOR_USE_SYMVER_SUN, [test "x$gfortran_use_symver" = xsun])
 
+AM_CONDITIONAL(LIBGFOR_MINIMAL, [test "x${target_cpu}" = xnvptx])
+
 # Figure out whether the compiler supports "-ffunction-sections -fdata-sections",
 # similarly to how libstdc++ does it
 ac_test_CFLAGS="${CFLAGS+set}"
diff --git a/libgfortran/runtime/compile_options.c b/libgfortran/runtime/compile_options.c
index 748ac23..6f78f9c 100644
--- a/libgfortran/runtime/compile_options.c
+++ b/libgfortran/runtime/compile_options.c
@@ -29,7 +29,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 /* Useful compile-time options will be stored in here.  */
 compile_options_t compile_options;
 
-
+#ifndef LIBGFOR_MINIMAL
 volatile sig_atomic_t fatal_error_in_progress = 0;
 
 
@@ -146,6 +146,7 @@ maybe_find_addr2line (void)
   if (options.backtrace == -1)
     find_addr2line ();
 }
+#endif
 
 /* Set the usual compile-time options.  */
 extern void set_options (int , int []);
@@ -176,6 +177,7 @@ set_options (int num, int options[])
   if (num >= 9)
     compile_options.fpe_summary = options[8];
 
+#ifndef LIBGFOR_MINIMAL
   /* If backtrace is required, we set signal handlers on the POSIX
      2001 signals with core action.  */
   if (compile_options.backtrace)
@@ -212,6 +214,7 @@ set_options (int num, int options[])
 
       maybe_find_addr2line ();
     }
+#endif
 }
 
 
diff --git a/libgfortran/runtime/minimal.c b/libgfortran/runtime/minimal.c
new file mode 100644
index 0000000..8dede63
--- /dev/null
+++ b/libgfortran/runtime/minimal.c
@@ -0,0 +1,158 @@
+/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
+   Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
+
+This file is part of the GNU Fortran runtime library (libgfortran).
+
+Libgfortran 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.
+
+Libgfortran 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/>.  */
+
+#include "libgfortran.h"
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <errno.h>
+
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* Stupid function to be sure the constructor is always linked in, even
+   in the case of static linking.  See PR libfortran/22298 for details.  */
+void
+stupid_function_name_for_static_linking (void)
+{
+  return;
+}
+
+options_t options;
+
+/* This will be 0 for little-endian
+   machines and 1 for big-endian machines.
+
+   Currently minimal libgfortran only runs on little-endian devices
+   which don't support constructors so this is just a constant.  */
+int big_endian = 0;
+
+static int argc_save;
+static char **argv_save;
+
+static const char *exe_path;
+
+/* recursion_check()-- It's possible for additional errors to occur
+ * during fatal error processing.  We detect this condition here and
+ * exit with code 4 immediately. */
+
+#define MAGIC 0x20DE8101
+
+static void
+recursion_check (void)
+{
+  static int magic = 0;
+
+  /* Don't even try to print something at this point */
+  if (magic == MAGIC)
+    sys_abort ();
+
+  magic = MAGIC;
+}
+
+#define STRERR_MAXSZ 256
+
+void
+os_error (const char *message)
+{
+  recursion_check ();
+  printf ("Operating system error: ");
+  printf ("%s\n", message);
+  exit (1);
+}
+iexport(os_error);
+
+void
+runtime_error (const char *message, ...)
+{
+  va_list ap;
+
+  recursion_check ();
+  printf ("Fortran runtime error: ");
+  va_start (ap, message);
+  vprintf (message, ap);
+  va_end (ap);
+  printf ("\n");
+  exit (2);
+}
+iexport(runtime_error);
+
+/* void runtime_error_at()-- These are errors associated with a
+ * run time error generated by the front end compiler.  */
+
+void
+runtime_error_at (const char *where, const char *message, ...)
+{
+  va_list ap;
+
+  recursion_check ();
+  printf ("Fortran runtime error: ");
+  va_start (ap, message);
+  vprintf (message, ap);
+  va_end (ap);
+  printf ("\n");
+  exit (2);
+}
+iexport(runtime_error_at);
+
+/* Return the full path of the executable.  */
+char *
+full_exe_path (void)
+{
+  return (char *) exe_path;
+}
+
+
+/* Set the saved values of the command line arguments.  */
+
+void
+set_args (int argc, char **argv)
+{
+  argc_save = argc;
+  argv_save = argv;
+  exe_path = argv[0];
+}
+iexport(set_args);
+
+
+/* Retrieve the saved values of the command line arguments.  */
+
+void
+get_args (int *argc, char ***argv)
+{
+  *argc = argc_save;
+  *argv = argv_save;
+}
+
+/* sys_abort()-- Terminate the program showing backtrace and dumping
+   core.  */
+
+void
+sys_abort (void)
+{
+  printf ("Abort called.\n");
+  abort();
+}

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-14 17:21   ` Bernd Schmidt
@ 2014-11-14 21:39     ` Tobias Burnus
  2014-11-15  7:03       ` Janne Blomqvist
  2014-11-28 18:49       ` Bernd Schmidt
  2015-03-11 21:48     ` Thomas Schwinge
  1 sibling, 2 replies; 21+ messages in thread
From: Tobias Burnus @ 2014-11-14 21:39 UTC (permalink / raw)
  To: Bernd Schmidt, GCC Patches, gfortran

Hi Tobias,

Bernd Schmidt wrote:
>> Does printf work? I thought I/O is not supported? Or does it just accept
>> it for linking and drop it? I think Janne's patch has already dealt with
>> the issue of stack allocation.
>
> printf (or more accurately vprintf) is supported by ptx as a magic 
> builtin function. We have a printf wrapper around vprintf in our newlib.

And that prints to the normal screen? That makes debugging easier than I 
had hoped for.

> What was Janne's patch?

He changed stack allocation to static/heap allocation; the patch was 
committed 36h ago, broke Cesar's bootstrap and is here: 
https://gcc.gnu.org/ml/fortran/2014-11/msg00052.html


>> What I dislike a bit about the feature is that it is not clear what
>> features will be supported for LIBGFOR_MINIMAL. Maybe configure.ac would
>> be a good place to describe which features are included there (e.g. no
>> I/O but "printf" etc.) and which aren't. That will make it easier to see
>> what has to be modifed if one will add another differently bare system
>> later on.
>
> My view is that it makes no sense to generalize this at the moment 
> when it is unknown what another target that uses this would look like. 
> The time to revisit this is when there is another target.

Well, one can still add some notes what is supported and what isn't – 
not only for that hypothecial case but also when doing other changes to 
the library (adding new functions).

>> Can't one write this differently, avoiding having most lines repeated
>> and only a few missing from the second set?
>
> Modified. New patch below, how does this look? Regenerated files not 
> included. Testing in progress.

I like it more that way :-)


All in all: Okay when tesing succeeded. I still prefer some words what's 
excluded (or included) in minimal as comment in configure.ac, but the 
patch is also okay without.

Thanks,

Tobias

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-14 21:39     ` Tobias Burnus
@ 2014-11-15  7:03       ` Janne Blomqvist
  2014-11-28 18:49       ` Bernd Schmidt
  1 sibling, 0 replies; 21+ messages in thread
From: Janne Blomqvist @ 2014-11-15  7:03 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Bernd Schmidt, GCC Patches, gfortran

On Fri, Nov 14, 2014 at 11:28 PM, Tobias Burnus <burnus@net-b.de> wrote:
> Hi Tobias,
>
> Bernd Schmidt wrote:
>>>
>>> Does printf work? I thought I/O is not supported? Or does it just accept
>>> it for linking and drop it? I think Janne's patch has already dealt with
>>> the issue of stack allocation.
>>
>>
>> printf (or more accurately vprintf) is supported by ptx as a magic builtin
>> function. We have a printf wrapper around vprintf in our newlib.

So the normal stdin/out/err file descriptors are not available?

> And that prints to the normal screen? That makes debugging easier than I had
> hoped for.
>
>> What was Janne's patch?
>
>
> He changed stack allocation to static/heap allocation; the patch was
> committed 36h ago, broke Cesar's bootstrap and is here:
> https://gcc.gnu.org/ml/fortran/2014-11/msg00052.html

To be fair, most of the fixes were in the I/O library, or for various
I/O related syscall wrappers, which probably aren't of interest for
the nvptx backend. In any case, libgfortran doesn't use alloca() nor
VLA's anymore, if there were any issues related to that when doing
your patch you might want to review it  and see if you can make the
minimal version a bit more complete.

>>> What I dislike a bit about the feature is that it is not clear what
>>> features will be supported for LIBGFOR_MINIMAL. Maybe configure.ac would
>>> be a good place to describe which features are included there (e.g. no
>>> I/O but "printf" etc.) and which aren't. That will make it easier to see
>>> what has to be modifed if one will add another differently bare system
>>> later on.
>>
>>
>> My view is that it makes no sense to generalize this at the moment when it
>> is unknown what another target that uses this would look like. The time to
>> revisit this is when there is another target.

Are you committed to helping whoever will be doing the support for the
next minimal target then? Otherwise it seems a bit unfair to leave it
to them to clean up the mess?

> Well, one can still add some notes what is supported and what isn't – not
> only for that hypothecial case but also when doing other changes to the
> library (adding new functions).

Yes, something like this would be nice. Otherwise it seems really easy
to inadvertently break nvptx.





-- 
Janne Blomqvist

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-14 21:39     ` Tobias Burnus
  2014-11-15  7:03       ` Janne Blomqvist
@ 2014-11-28 18:49       ` Bernd Schmidt
  1 sibling, 0 replies; 21+ messages in thread
From: Bernd Schmidt @ 2014-11-28 18:49 UTC (permalink / raw)
  To: Tobias Burnus, GCC Patches, gfortran

On 11/14/2014 10:28 PM, Tobias Burnus wrote:
> All in all: Okay when tesing succeeded. I still prefer some words what's
> excluded (or included) in minimal as comment in configure.ac, but the
> patch is also okay without.

I thought you meant something more than adding a comment. I've added 
this in the configure script, and committed the patch after testing:

# For GPU offloading, not everything in libfortran can be supported.
# Currently, the only target that has this problem is nvptx.  The
# following is a (partial) list of features that are unsupportable on
# this particular target:
# * Constructors
# * alloca
# * C library support for I/O, with printf as the one notable exception
# * C library support for other features such as signal, environment
#   variables, time functions

I wouldn't worry too much about breaking nvptx by accident, we can 
surely clean up any such problems should they arise.


Bernd

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2014-11-14 17:21   ` Bernd Schmidt
  2014-11-14 21:39     ` Tobias Burnus
@ 2015-03-11 21:48     ` Thomas Schwinge
  2019-10-08 10:23       ` Thomas Schwinge
  1 sibling, 1 reply; 21+ messages in thread
From: Thomas Schwinge @ 2015-03-11 21:48 UTC (permalink / raw)
  To: gcc-patches, fortran; +Cc: Bernd Schmidt

[-- Attachment #1: Type: text/plain, Size: 5263 bytes --]

Hi!

On Fri, 14 Nov 2014 18:08:32 +0100, Bernd Schmidt <bernds@codesourcery.com> wrote:
> New patch below, [...]

... got committed.  I now committed the following in r221363:

commit 83ba0e65833dd081db921f8c2b3277316590753c
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Mar 11 21:42:56 2015 +0000

    libgfortran LIBGFOR_MINIMAL enhancements.
    
    Based on GCC trunk r220892, for nvptx-none:
    
                        === gfortran Summary ===
    
        # of expected passes            [-31320-]{+32117+}
        # of unexpected failures        [-7222-]{+6821+}
        # of expected failures          78
        # of unresolved testcases       [-6441-]{+6158+}
        # of untested testcases         [-432-]{+391+}
        # of unsupported tests          639
    
    	libgfortran/
    	* caf/single.c (caf_runtime_error): Revert 2014-11-28 changes.
    	* runtime/minimal.c (STRERR_MAXSZ): Don't define.
    	(runtime_error_at, sys_abort): Bring more in line with the
    	non-LIBGFOR_MINIMAL code.
    	(runtime_warning_at, internal_error): New functions.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221363 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgfortran/ChangeLog         |    8 ++++++
 libgfortran/caf/single.c      |    3 +--
 libgfortran/runtime/minimal.c |   58 ++++++++++++++++++++++++++++++++++++++---
 3 files changed, 64 insertions(+), 5 deletions(-)

diff --git libgfortran/ChangeLog libgfortran/ChangeLog
index 97ee01b..5b201d2 100644
--- libgfortran/ChangeLog
+++ libgfortran/ChangeLog
@@ -1,3 +1,11 @@
+2015-03-11  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* caf/single.c (caf_runtime_error): Revert 2014-11-28 changes.
+	* runtime/minimal.c (STRERR_MAXSZ): Don't define.
+	(runtime_error_at, sys_abort): Bring more in line with the
+	non-LIBGFOR_MINIMAL code.
+	(runtime_warning_at, internal_error): New functions.
+
 2015-03-11  Janne Blomqvist  <jb@gcc.gnu.org>
 
 	PR libfortran/65200
diff --git libgfortran/caf/single.c libgfortran/caf/single.c
index daef281..6c58286 100644
--- libgfortran/caf/single.c
+++ libgfortran/caf/single.c
@@ -48,14 +48,13 @@ caf_static_t *caf_static_list = NULL;
 static void
 caf_runtime_error (const char *message, ...)
 {
-#ifndef LIBGFOR_MINIMAL
   va_list ap;
   fprintf (stderr, "Fortran runtime error: ");
   va_start (ap, message);
   vfprintf (stderr, message, ap);
   va_end (ap);
   fprintf (stderr, "\n");
-#endif
+
   /* FIXME: Shutdown the Fortran RTL to flush the buffer.  PR 43849.  */
   exit (EXIT_FAILURE);
 }
diff --git libgfortran/runtime/minimal.c libgfortran/runtime/minimal.c
index 7ef4647..72a134a 100644
--- libgfortran/runtime/minimal.c
+++ libgfortran/runtime/minimal.c
@@ -73,7 +73,10 @@ recursion_check (void)
   magic = MAGIC;
 }
 
-#define STRERR_MAXSZ 256
+
+/* os_error()-- Operating system error.  We get a message from the
+ * operating system, show it and leave.  Some operating system errors
+ * are caught and processed by the library.  If not, we come here. */
 
 void
 os_error (const char *message)
@@ -85,6 +88,10 @@ os_error (const char *message)
 }
 iexport(os_error);
 
+
+/* void runtime_error()-- These are errors associated with an
+ * invalid fortran program. */
+
 void
 runtime_error (const char *message, ...)
 {
@@ -109,7 +116,8 @@ runtime_error_at (const char *where, const char *message, ...)
   va_list ap;
 
   recursion_check ();
-  printf ("Fortran runtime error: ");
+  printf ("%s", where);
+  printf ("\nFortran runtime error: ");
   va_start (ap, message);
   vprintf (message, ap);
   va_end (ap);
@@ -118,6 +126,43 @@ runtime_error_at (const char *where, const char *message, ...)
 }
 iexport(runtime_error_at);
 
+
+void
+runtime_warning_at (const char *where, const char *message, ...)
+{
+  va_list ap;
+
+  printf ("%s", where);
+  printf ("\nFortran runtime warning: ");
+  va_start (ap, message);
+  vprintf (message, ap);
+  va_end (ap);
+  printf ("\n");
+}
+iexport(runtime_warning_at);
+
+
+/* void internal_error()-- These are this-can't-happen errors
+ * that indicate something deeply wrong. */
+
+void
+internal_error (st_parameter_common *cmp, const char *message)
+{
+  recursion_check ();
+  printf ("Internal Error: ");
+  printf ("%s", message);
+  printf ("\n");
+
+  /* This function call is here to get the main.o object file included
+     when linking statically. This works because error.o is supposed to
+     be always linked in (and the function call is in internal_error
+     because hopefully it doesn't happen too often).  */
+  stupid_function_name_for_static_linking();
+
+  exit (3);
+}
+
+
 /* Return the full path of the executable.  */
 char *
 full_exe_path (void)
@@ -153,6 +198,13 @@ get_args (int *argc, char ***argv)
 void
 sys_abort (void)
 {
-  printf ("Abort called.\n");
+  /* If backtracing is enabled, print backtrace and disable signal
+     handler for ABRT.  */
+  if (options.backtrace == 1
+      || (options.backtrace == -1 && compile_options.backtrace == 1))
+    {
+      printf ("\nProgram aborted.\n");
+    }
+
   abort();
 }


Grüße,
 Thomas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: RFC: Building a minimal libgfortran for nvptx
  2015-03-11 21:48     ` Thomas Schwinge
@ 2019-10-08 10:23       ` Thomas Schwinge
  0 siblings, 0 replies; 21+ messages in thread
From: Thomas Schwinge @ 2019-10-08 10:23 UTC (permalink / raw)
  To: gcc-patches, fortran


[-- Attachment #1.1: Type: text/plain, Size: 448 bytes --]

Hi!

On 2015-03-11T22:48:22+0100, I wrote:
> On Fri, 14 Nov 2014 18:08:32 +0100, Bernd Schmidt <bernds@codesourcery.com> wrote:
>> New patch below, [...]
>
> ... got committed.  I now committed the following in r221363:

>     libgfortran LIBGFOR_MINIMAL enhancements.

..., and in r276690 have now committed the attached to "Revise
'libgfortran/runtime/minimal.c' to better conform to the original
sources".


Grüße
 Thomas



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Revise-libgfortran-runtime-minimal.c-to-better.trunk.patch --]
[-- Type: text/x-diff, Size: 8549 bytes --]

From c6c3841de5ec2b37d8b579bd7bce54bef811c064 Mon Sep 17 00:00:00 2001
From: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 8 Oct 2019 10:20:31 +0000
Subject: [PATCH 1/3] Revise 'libgfortran/runtime/minimal.c' to better conform
 to the original sources

	libgfortran/
	* runtime/minimal.c: Revise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@276690 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgfortran/ChangeLog         |   4 +
 libgfortran/runtime/minimal.c | 237 +++++++++++++++++++++++-----------
 2 files changed, 169 insertions(+), 72 deletions(-)

diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 7736e5da937..9e3b1f8bad8 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,7 @@
+2019-10-08  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* runtime/minimal.c: Revise.
+
 2019-10-05  Paul Thomas  <pault@gcc.gnu.org>
 
 	PR fortran/91926
diff --git a/libgfortran/runtime/minimal.c b/libgfortran/runtime/minimal.c
index c1993b99be7..a633bc1ce0f 100644
--- a/libgfortran/runtime/minimal.c
+++ b/libgfortran/runtime/minimal.c
@@ -23,13 +23,38 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
-#include <string.h>
 
+#include <string.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
+
+#if __nvptx__
+/* Map "exit" to "abort"; see PR85463 '[nvptx] "exit" in offloaded region
+   doesn't terminate process'.  */
+# undef exit
+# define exit(status) do { (void) (status); abort (); } while (0)
+#endif
+
+
+#if __nvptx__
+/* 'printf' is all we have.  */
+# undef estr_vprintf
+# define estr_vprintf vprintf
+#else
+# error TODO
+#endif
+
+
+/* runtime/environ.c */
+
+options_t options;
+
+
+/* runtime/main.c */
+
 /* Stupid function to be sure the constructor is always linked in, even
    in the case of static linking.  See PR libfortran/22298 for details.  */
 void
@@ -38,11 +63,126 @@ stupid_function_name_for_static_linking (void)
   return;
 }
 
-options_t options;
 
 static int argc_save;
 static char **argv_save;
 
+
+/* Set the saved values of the command line arguments.  */
+
+void
+set_args (int argc, char **argv)
+{
+  argc_save = argc;
+  argv_save = argv;
+}
+iexport(set_args);
+
+
+/* Retrieve the saved values of the command line arguments.  */
+
+void
+get_args (int *argc, char ***argv)
+{
+  *argc = argc_save;
+  *argv = argv_save;
+}
+
+
+/* runtime/error.c */
+
+/* Write a null-terminated C string to standard error. This function
+   is async-signal-safe.  */
+
+ssize_t
+estr_write (const char *str)
+{
+  return write (STDERR_FILENO, str, strlen (str));
+}
+
+
+/* printf() like function for for printing to stderr.  Uses a stack
+   allocated buffer and doesn't lock stderr, so it should be safe to
+   use from within a signal handler.  */
+
+int
+st_printf (const char * format, ...)
+{
+  int written;
+  va_list ap;
+  va_start (ap, format);
+  written = estr_vprintf (format, ap);
+  va_end (ap);
+  return written;
+}
+
+
+/* sys_abort()-- Terminate the program showing backtrace and dumping
+   core.  */
+
+void
+sys_abort (void)
+{
+  /* If backtracing is enabled, print backtrace and disable signal
+     handler for ABRT.  */
+  if (options.backtrace == 1
+      || (options.backtrace == -1 && compile_options.backtrace == 1))
+    {
+      estr_write ("\nProgram aborted.\n");
+    }
+
+  abort();
+}
+
+
+/* Exit in case of error termination. If backtracing is enabled, print
+   backtrace, then exit.  */
+
+void
+exit_error (int status)
+{
+  if (options.backtrace == 1
+      || (options.backtrace == -1 && compile_options.backtrace == 1))
+    {
+      estr_write ("\nError termination.\n");
+    }
+  exit (status);
+}
+
+
+/* show_locus()-- Print a line number and filename describing where
+ * something went wrong */
+
+void
+show_locus (st_parameter_common *cmp)
+{
+  char *filename;
+
+  if (!options.locus || cmp == NULL || cmp->filename == NULL)
+    return;
+  
+  if (cmp->unit > 0)
+    {
+      filename = /* TODO filename_from_unit (cmp->unit) */ NULL;
+
+      if (filename != NULL)
+	{
+	  st_printf ("At line %d of file %s (unit = %d, file = '%s')\n",
+		   (int) cmp->line, cmp->filename, (int) cmp->unit, filename);
+	  free (filename);
+	}
+      else
+	{
+	  st_printf ("At line %d of file %s (unit = %d)\n",
+		   (int) cmp->line, cmp->filename, (int) cmp->unit);
+	}
+      return;
+    }
+
+  st_printf ("At line %d of file %s\n", (int) cmp->line, cmp->filename);
+}
+
+
 /* recursion_check()-- It's possible for additional errors to occur
  * during fatal error processing.  We detect this condition here and
  * exit with code 4 immediately. */
@@ -70,9 +210,10 @@ void
 os_error (const char *message)
 {
   recursion_check ();
-  printf ("Operating system error: ");
-  printf ("%s\n", message);
-  exit (1);
+  estr_write ("Operating system error: ");
+  estr_write (message);
+  estr_write ("\n");
+  exit_error (1);
 }
 iexport(os_error);
 
@@ -86,12 +227,12 @@ runtime_error (const char *message, ...)
   va_list ap;
 
   recursion_check ();
-  printf ("Fortran runtime error: ");
+  estr_write ("Fortran runtime error: ");
   va_start (ap, message);
-  vprintf (message, ap);
+  estr_vprintf (message, ap);
   va_end (ap);
-  printf ("\n");
-  exit (2);
+  estr_write ("\n");
+  exit_error (2);
 }
 iexport(runtime_error);
 
@@ -104,13 +245,13 @@ runtime_error_at (const char *where, const char *message, ...)
   va_list ap;
 
   recursion_check ();
-  printf ("%s", where);
-  printf ("\nFortran runtime error: ");
+  estr_write (where);
+  estr_write ("\nFortran runtime error: ");
   va_start (ap, message);
-  vprintf (message, ap);
+  estr_vprintf (message, ap);
   va_end (ap);
-  printf ("\n");
-  exit (2);
+  estr_write ("\n");
+  exit_error (2);
 }
 iexport(runtime_error_at);
 
@@ -120,12 +261,12 @@ runtime_warning_at (const char *where, const char *message, ...)
 {
   va_list ap;
 
-  printf ("%s", where);
-  printf ("\nFortran runtime warning: ");
+  estr_write (where);
+  estr_write ("\nFortran runtime warning: ");
   va_start (ap, message);
-  vprintf (message, ap);
+  estr_vprintf (message, ap);
   va_end (ap);
-  printf ("\n");
+  estr_write ("\n");
 }
 iexport(runtime_warning_at);
 
@@ -137,9 +278,10 @@ void
 internal_error (st_parameter_common *cmp, const char *message)
 {
   recursion_check ();
-  printf ("Internal Error: ");
-  printf ("%s", message);
-  printf ("\n");
+  show_locus (cmp);
+  estr_write ("Internal Error: ");
+  estr_write (message);
+  estr_write ("\n");
 
   /* This function call is here to get the main.o object file included
      when linking statically. This works because error.o is supposed to
@@ -147,45 +289,7 @@ internal_error (st_parameter_common *cmp, const char *message)
      because hopefully it doesn't happen too often).  */
   stupid_function_name_for_static_linking();
 
-  exit (3);
-}
-
-
-/* Set the saved values of the command line arguments.  */
-
-void
-set_args (int argc, char **argv)
-{
-  argc_save = argc;
-  argv_save = argv;
-}
-iexport(set_args);
-
-
-/* Retrieve the saved values of the command line arguments.  */
-
-void
-get_args (int *argc, char ***argv)
-{
-  *argc = argc_save;
-  *argv = argv_save;
-}
-
-/* sys_abort()-- Terminate the program showing backtrace and dumping
-   core.  */
-
-void
-sys_abort (void)
-{
-  /* If backtracing is enabled, print backtrace and disable signal
-     handler for ABRT.  */
-  if (options.backtrace == 1
-      || (options.backtrace == -1 && compile_options.backtrace == 1))
-    {
-      printf ("\nProgram aborted.\n");
-    }
-
-  abort();
+  exit_error (3);
 }
 
 
@@ -193,18 +297,7 @@ sys_abort (void)
 
 #undef report_exception
 #define report_exception() do {} while (0)
-#undef st_printf
-#define st_printf printf
-#undef estr_write
-#define estr_write(X) write(STDERR_FILENO, (X), strlen (X))
-#if __nvptx__
-/* Map "exit" to "abort"; see PR85463 '[nvptx] "exit" in offloaded region
-   doesn't terminate process'.  */
-#undef exit
-#define exit(...) do { abort (); } while (0)
-#endif
-#undef exit_error
-#define exit_error(...) do { abort (); } while (0)
+
 
 /* A numeric STOP statement.  */
 
-- 
2.17.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 658 bytes --]

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

end of thread, other threads:[~2019-10-08 10:23 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-04 14:38 RFC: Building a minimal libgfortran for nvptx Bernd Schmidt
2014-11-04 15:41 ` Steve Kargl
2014-11-04 15:58   ` Bernd Schmidt
2014-11-04 17:08     ` Steve Kargl
2014-11-04 18:19     ` Jeff Law
2014-11-04 16:12   ` Jakub Jelinek
2014-11-04 16:15     ` FX
2014-11-04 16:19       ` Jakub Jelinek
2014-11-04 17:11         ` FX
2014-11-04 17:21     ` Jeff Law
2014-11-04 17:38       ` Steve Kargl
2014-11-04 18:44       ` N.M. Maclaren
2014-11-04 15:59 ` FX
2014-11-04 16:10   ` Bernd Schmidt
2014-11-13 22:14 ` Tobias Burnus
2014-11-14 17:21   ` Bernd Schmidt
2014-11-14 21:39     ` Tobias Burnus
2014-11-15  7:03       ` Janne Blomqvist
2014-11-28 18:49       ` Bernd Schmidt
2015-03-11 21:48     ` Thomas Schwinge
2019-10-08 10:23       ` Thomas Schwinge

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).