On Tue, Jun 27, 2017 at 09:17:57AM +0200, Tom de Vries wrote:
> This patch uses secure_getenv for GOMP_DEBUG.
> 
> It factors out the secure_getenv code from plugin-hsa.c into
> libgomp/secure_getenv.h, and reuses it in env.c.
> 
> I've added _GNU_SOURCE before the libgomp.h include in env.c to make sure
> that secure_getenv (imported from stdlib.h) is available.
> 
> I've also added a test-case that sets GOMP_DEBUG to 1 and verifies that some
> output is generated.
> 
> Build for c-only on x86_64 without accelerator, tested libgomp -m64/-m32.
> 
> OK if x86_64 bootstrap and reg-test succeeds?
> 
> Thanks,
> - Tom

> Use secure_getenv for GOMP_DEBUG
> 

> --- /dev/null
> +++ b/libgomp/secure_getenv.h
> @@ -0,0 +1,53 @@
> +/* Copyright (C) 2017 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC 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.
> +
> +GCC 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/>.  */
> +
> +#ifndef _SECURE_GETENV_H
> +#define _SECURE_GETENV_H 1
> +
> +/* Secure getenv() which returns NULL if running as SUID/SGID.  */
> +#ifndef HAVE_SECURE_GETENV
> +#ifdef HAVE___SECURE_GETENV
> +#define secure_getenv __secure_getenv
> +#elif defined (HAVE_UNISTD_H) && defined(HAVE_GETUID) && 
> defined(HAVE_GETEUID) \
> +  && defined(HAVE_GETGID) && defined(HAVE_GETEGID)
> +
> +#include <unistd.h>
> +
> +/* Implementation of secure_getenv() for targets where it is not provided but
> +   we have at least means to test real and effective IDs.  */
> +
> +static char *
> +secure_getenv (const char *name)

Shouldn't this be static inline char * ?  I mean, even at -O0 we don't want
it to be emitted into every TU.

Another thing is that we probably want to follow what libgfortran does for
the case where secure_getenv isn't available, but __secure_getenv is -
in particular emit this function (if geteuid and getegid are present), but
emit a weakref call to __secure_getenv first if non-NULL.

> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/gomp-debug-env.c
> @@ -0,0 +1,13 @@
> +/* { dg-do run } */
> +/* { dg-set-target-env-var GOMP_DEBUG "1" } */
> +
> +/* Check that GOMP_DEBUG=1 triggers some output.  */
> +
> +int
> +main (void)
> +{
> +#pragma acc parallel
> +  ;
> +}
> +
> +/* { dg-output "GOACC_parallel_keyed" } */

Does dg-set-target-env-var work for remote testing?

        Jakub

Reply via email to