This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On 09/28/2015 11:20 AM, Marcin KoÅcielnicki wrote:
>> A function address would have all the requirements for alignment that you would
>> need to avoid this problem.
> 
> Sorry, I don't get what you're talking about.

This is an artificial address of 1, which is why it is violating assumptions in
the s390x implementation. If the address had been that of a function, we would
not have seen this failure.

We might add a way to create valid addresses from flags and vice versa using a
macro from libc-symbols.h as Mike suggests.

Totally untested:

sysdeps/generic/libc-symbols.h
/* On a generic machine any symbol address is valid.  */
#define FLAGS_TO_SYMADDR(val) (val)
#define SYMADDR_TO_FLAGS(val) (val)
#include_next <libc-symbols.h>

sysdeps/s390/libc-symbols.h
/* On s390 a symbol address must be aligned to X. Therefore if we hide
flags in a symbol address we loose the lowest bits for flags. */
#define FLAGS_TO_SYMADDR(val) (val << X)
#define SYMADDR_TO_FLAGS(val) (val >> X)
#include_next <libc-symbols.h>

locale/localeinfo.h:
/* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY.  */
#define _NL_CURRENT_DEFINE(category) \
  __thread struct __locale_data *const *_nl_current_##category \
    attribute_hidden = &_nl_global_locale.__locales[category]; \
  asm (".globl " __SYMBOL_PREFIX "_nl_current_" #category "_used\n" \
       _NL_CURRENT_DEFINE_ABS (_nl_current_##category##_used,
			       FLAGS_TO_SYMADDR (1)));

...
locale/uselocale.c:
# define DEFINE_CATEGORY(category, category_name, items, a) \
      {                                                                       \
        extern char _nl_current_##category##_used;                            \
        weak_extern (_nl_current_##category##_used)                           \
        weak_extern (_nl_current_##category)                                  \
        if (SYMADDR_TO_FLAGS(&_nl_current_##category##_used) != 0)            \
          _nl_current_##category = &locobj->__locales[category];              \
      }

Does that make sense?

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]