Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jun 2017 13:03:24 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Eric van Gyzen <vangyzen@FreeBSD.org>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>, toolchain@freebsd.org
Subject:   Re: Function attribute for optimization level
Message-ID:  <20170605100324.GV82323@kib.kiev.ua>
In-Reply-To: <85c47390-dd27-aa74-24fe-25a9a5352527@FreeBSD.org>
References:  <85c47390-dd27-aa74-24fe-25a9a5352527@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
I think that toolchain@ is more suitable list for the discussion.

On Sun, Jun 04, 2017 at 05:44:31PM -0500, Eric van Gyzen wrote:
> _thr_rtld_init() calls memcpy() for the sole purpose of resolving its
> PLT entry. With clang 4.0 and the current code, compiler optimization
> defeats this attempt by completely eliding the call. Other compilers
> or code might emit inline instructions instead of the library call,
> also defeating the purpose.
After looking more closely at the whole situation, I have a question
that we probably must answer first.  Is clang -ffreestanding mode
broken ?  memcpy(3) is not included into the set of the environment
features required for a C11 freestanding implementation,  and clang
pretending that it knows the semantic of the call sounds broken.

>
> I propose adding "__no_optimization" to sys/cdefs.h. The patch is
> below. Empirical testing shows that clang 3.7 and later support
> "optnone", and gcc 4.6 and later support "optimize()". Clang 3.4 does
> not support either, so it takes the define-to-empty case. I did not
> test clang 3.5 or 3.6.
Where this attribute should be applied ?  To the _thr_rtld_init() function ?

>
> Side note: GCC 4.6 with optimize(0) on amd64 emits two movq
> instructions for memset(x,0,16), but GCC 5 emits a call to memset().
>
> I have done no research to see if other popular codebases have such a
> definition. If you know of one, please tell me; I would gladly adopt
> an already common name for this proposal, for the sake of portability.
>
> Thanks in advance for your feedback.
>
> Eric
>
>
> diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index
> 9cdc03c861cb..e370f6d6459e 100644 --- a/sys/sys/cdefs.h +++
> b/sys/sys/cdefs.h @@ -396,6 +396,14 @@ #define __unreachable()
> ((void)0) #endif
>
> +#if __has_attribute(optnone) +#define __no_optimization
> __attribute__((optnone)) +#elif __has_attribute(optimize) +#define
> __no_optimization __attribute__((optimize(0))) +#else +#define
> __no_optimization +#endif + /* XXX: should use `#if __STDC_VERSION__ <
> 199901'. */ #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
> #define __func__ NULL _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to
> "freebsd-hackers-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170605100324.GV82323>