diff mbox

[3/3] Move data definitions from icv.c back to env.c

Message ID alpine.LNX.2.20.13.1611302028100.9298@monopod.intra.ispras.ru
State New
Headers show

Commit Message

Alexander Monakov Nov. 30, 2016, 5:36 p.m. UTC
env.c contains a static constructor that would initialize various global libgomp
data such as members of gomp_global_icv.  Therefore it's not ok to define them
in a separate translation unit: under static linking this results in env.o not
linked in (unless an incremental link on icv.o+env.o is performed when building
libgomp.a).  Move definitions of global data from icv.c back to env.c, remove
empty config/nvptx/env.c, and guard environment access on NVPTX using the new
LIBGOMP_OFFLOADED_ONLY macro.

	* config/nvptx/env.c: Delete.
	* icv.c: Move definitions of ICV variables back ...
	* env.c: ...here.  Do not compile environment-related functionality if
	LIBGOMP_OFFLOADED_ONLY is set.

Comments

Jakub Jelinek Nov. 30, 2016, 5:50 p.m. UTC | #1
On Wed, Nov 30, 2016 at 08:36:27PM +0300, Alexander Monakov wrote:
> env.c contains a static constructor that would initialize various global libgomp
> data such as members of gomp_global_icv.  Therefore it's not ok to define them
> in a separate translation unit: under static linking this results in env.o not
> linked in (unless an incremental link on icv.o+env.o is performed when building
> libgomp.a).  Move definitions of global data from icv.c back to env.c, remove
> empty config/nvptx/env.c, and guard environment access on NVPTX using the new
> LIBGOMP_OFFLOADED_ONLY macro.
> 
> 	* config/nvptx/env.c: Delete.
> 	* icv.c: Move definitions of ICV variables back ...
> 	* env.c: ...here.  Do not compile environment-related functionality if
> 	LIBGOMP_OFFLOADED_ONLY is set.

Can you please move the ICVs after all the (especially system) headers are included,
even when it means 2 separate #ifndef LIBGOMP_OFFLOADED_ONLY instead of just
one?  Ok with that change.

	Jakub
diff mbox

Patch

diff --git a/libgomp/config/nvptx/env.c b/libgomp/config/nvptx/env.c
deleted file mode 100644
index e69de29..0000000
diff --git a/libgomp/env.c b/libgomp/env.c
index 7ba7663..d601e19 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -23,13 +23,46 @@ 
    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-/* This file arranges for OpenMP internal control variables to be initialized
-   from environment variables at startup.  */
+/* This file defines the OpenMP internal control variables and arranges
+   for them to be initialized from environment variables at startup.  */
 
 #include "libgomp.h"
+#include "gomp-constants.h"
+#include <limits.h>
+
+struct gomp_task_icv gomp_global_icv = {
+  .nthreads_var = 1,
+  .thread_limit_var = UINT_MAX,
+  .run_sched_var = GFS_DYNAMIC,
+  .run_sched_chunk_size = 1,
+  .default_device_var = 0,
+  .dyn_var = false,
+  .nest_var = false,
+  .bind_var = omp_proc_bind_false,
+  .target_data = NULL
+};
+
+unsigned long gomp_max_active_levels_var = INT_MAX;
+bool gomp_cancel_var = false;
+int gomp_max_task_priority_var = 0;
+#ifndef HAVE_SYNC_BUILTINS
+gomp_mutex_t gomp_managed_threads_lock;
+#endif
+unsigned long gomp_available_cpus = 1, gomp_managed_threads = 1;
+unsigned long long gomp_spin_count_var, gomp_throttled_spin_count_var;
+unsigned long *gomp_nthreads_var_list, gomp_nthreads_var_list_len;
+char *gomp_bind_var_list;
+unsigned long gomp_bind_var_list_len;
+void **gomp_places_list;
+unsigned long gomp_places_list_len;
+int gomp_debug_var;
+unsigned int gomp_num_teams_var;
+char *goacc_device_type;
+int goacc_device_num;
+
+#ifndef LIBGOMP_OFFLOADED_ONLY
 #include "libgomp_f.h"
 #include "oacc-int.h"
-#include "gomp-constants.h"
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -48,7 +81,6 @@ 
 #  endif
 # endif
 #endif
-#include <limits.h>
 #include <errno.h>
 
 #ifndef HAVE_STRTOULL
@@ -1273,3 +1305,4 @@  initialize_env (void)
 
   goacc_runtime_initialize ();
 }
+#endif /* LIBGOMP_OFFLOADED_ONLY */
diff --git a/libgomp/icv.c b/libgomp/icv.c
index e58b961..cf00e24 100644
--- a/libgomp/icv.c
+++ b/libgomp/icv.c
@@ -23,43 +23,13 @@ 
    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    <http://www.gnu.org/licenses/>.  */
 
-/* This file defines the OpenMP internal control variables and associated
-   OpenMP API entry points.  */
+/* This file defines the OpenMP API entry points that operate on internal
+   control variables.  */
 
 #include "libgomp.h"
 #include "gomp-constants.h"
 #include <limits.h>
 
-struct gomp_task_icv gomp_global_icv = {
-  .nthreads_var = 1,
-  .thread_limit_var = UINT_MAX,
-  .run_sched_var = GFS_DYNAMIC,
-  .run_sched_chunk_size = 1,
-  .default_device_var = 0,
-  .dyn_var = false,
-  .nest_var = false,
-  .bind_var = omp_proc_bind_false,
-  .target_data = NULL
-};
-
-unsigned long gomp_max_active_levels_var = INT_MAX;
-bool gomp_cancel_var = false;
-int gomp_max_task_priority_var = 0;
-#ifndef HAVE_SYNC_BUILTINS
-gomp_mutex_t gomp_managed_threads_lock;
-#endif
-unsigned long gomp_available_cpus = 1, gomp_managed_threads = 1;
-unsigned long long gomp_spin_count_var, gomp_throttled_spin_count_var;
-unsigned long *gomp_nthreads_var_list, gomp_nthreads_var_list_len;
-char *gomp_bind_var_list;
-unsigned long gomp_bind_var_list_len;
-void **gomp_places_list;
-unsigned long gomp_places_list_len;
-int gomp_debug_var;
-unsigned int gomp_num_teams_var;
-char *goacc_device_type;
-int goacc_device_num;
-
 void
 omp_set_num_threads (int n)
 {