[PATCH][BZ 18960] setlocale.c: Mark *_used symbols as unaligned.

Florian Weimer fweimer@redhat.com
Mon Sep 28 13:16:00 GMT 2015


On 09/27/2015 03:26 PM, Marcin Kościelnicki wrote:
> This ensures that compiler doesn't get the values of these symbols
> using instructions that have alignment requirements (eg. larl on s390).

The commit message should perhaps say “the address of these variables”
because the trigger for this issue is in C code, so it makes sense to
use C terms.

> ---
>  locale/setlocale.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/locale/setlocale.c b/locale/setlocale.c
> index ead030d..028496d 100644
> --- a/locale/setlocale.c
> +++ b/locale/setlocale.c
> @@ -35,7 +35,7 @@
>     Also use a weak reference for the _nl_current_CATEGORY thread variable.  */
>  
>  # define DEFINE_CATEGORY(category, category_name, items, a) \
> -    extern char _nl_current_##category##_used; \
> +    extern char _nl_current_##category##_used __attribute__((__aligned__(1))); \

This is a very gray area as far as GCC is concerned.  This side effect
of attributed “aligned” is not documented, and I'm not sure if we can
rely on it.  It's a bit like making a non-weak function symbol zero.

Maybe the better approach would be to change 1 to 8 or 16.

-- 
Florian Weimer / Red Hat Product Security



More information about the Libc-alpha mailing list