This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: locale files and int32_t alignment
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: <libc-alpha at sourceware dot org>
- Date: Thu, 12 Sep 2013 21:08:14 +0000
- Subject: Re: locale files and int32_t alignment
- Authentication-results: sourceware.org; auth=none
- References: <Pine dot LNX dot 4 dot 64 dot 1309040055321 dot 27960 at digraph dot polyomino dot org dot uk> <mvmli324c48 dot fsf at hawking dot suse dot de>
On Thu, 12 Sep 2013, Andreas Schwab wrote:
> "Joseph S. Myers" <joseph@codesourcery.com> writes:
>
> > Perhaps we should actually change the relevant code - in both
> > localedef and libc - to use sizeof instead of alignof, and so
> > eliminate this architecture dependence?
>
> I'd prefer this approach.
This patch makes that change to use sizeof to eliminate this
architecture-dependence.
Tested (with the glibc testsuite) on x86_64; the installed shared
libraries are identical before and after the patch, while the changes
to the disassembly of the localedef binary all appear harmless
(consequent on changes to the strings that are the text of assertions,
because some of the changes are inside calls to assert). Of course,
that's not the most relevant testing for this change; what would be
more relevant is testing on m68k (a) that localedef and locales still
work OK and (b) that the generated locales are identical to those on
other systems, given the same signedness of char or
<https://sourceware.org/ml/libc-alpha/2013-09/msg00425.html> applied,
the same page size or the getpagesize call in locarchive.c hacked
around, and the same endianness or
<https://sourceware.org/ml/libc-alpha/2013-09/msg00413.html> applied
and used to generate other-endian locales.
2013-09-12 Joseph Myers <joseph@codesourcery.com>
* locale/programs/ld-collate.c (collate_output): Use sizeof
(int32_t) instead of __alignof__ (int32_t).
* locale/weight.h (findidx): Likewise.
diff --git a/locale/programs/ld-collate.c b/locale/programs/ld-collate.c
index c4d7e3d..79415d8 100644
--- a/locale/programs/ld-collate.c
+++ b/locale/programs/ld-collate.c
@@ -2151,11 +2151,11 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
++i;
}
/* And align the output. */
- i = (nrules * i) % __alignof__ (int32_t);
+ i = (nrules * i) % sizeof (int32_t);
if (i > 0)
do
obstack_1grow (&weightpool, '\0');
- while (++i < __alignof__ (int32_t));
+ while (++i < sizeof (int32_t));
add_locale_raw_obstack (&file, &weightpool);
@@ -2202,7 +2202,7 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
struct element_t *lastp;
assert ((obstack_object_size (&extrapool)
- & (__alignof__ (int32_t) - 1)) == 0);
+ & (sizeof (int32_t) - 1)) == 0);
tablemb[ch] = -obstack_object_size (&extrapool);
@@ -2228,10 +2228,10 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
/* Compute how much space we will need. */
added = ((sizeof (int32_t) + 1 + 2 * (runp->nmbs - 1)
- + __alignof__ (int32_t) - 1)
- & ~(__alignof__ (int32_t) - 1));
+ + sizeof (int32_t) - 1)
+ & ~(sizeof (int32_t) - 1));
assert ((obstack_object_size (&extrapool)
- & (__alignof__ (int32_t) - 1)) == 0);
+ & (sizeof (int32_t) - 1)) == 0);
obstack_make_room (&extrapool, added);
/* More than one consecutive entry. We mark this by having
@@ -2289,10 +2289,10 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
weightidx = output_weight (&weightpool, collate, runp);
added = ((sizeof (int32_t) + 1 + runp->nmbs - 1
- + __alignof__ (int32_t) - 1)
- & ~(__alignof__ (int32_t) - 1));
+ + sizeof (int32_t) - 1)
+ & ~(sizeof (int32_t) - 1));
assert ((obstack_object_size (&extrapool)
- & (__alignof__ (int32_t) - 1)) == 0);
+ & (sizeof (int32_t) - 1)) == 0);
obstack_make_room (&extrapool, added);
obstack_int32_grow_fast (&extrapool, weightidx);
@@ -2305,7 +2305,7 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
/* Add alignment bytes if necessary. */
while ((obstack_object_size (&extrapool)
- & (__alignof__ (int32_t) - 1)) != 0)
+ & (sizeof (int32_t) - 1)) != 0)
obstack_1grow_fast (&extrapool, '\0');
/* Next entry. */
@@ -2315,14 +2315,14 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
while (runp != NULL);
assert ((obstack_object_size (&extrapool)
- & (__alignof__ (int32_t) - 1)) == 0);
+ & (sizeof (int32_t) - 1)) == 0);
/* If the final entry in the list is not a single character we
add an UNDEFINED entry here. */
if (lastp->nmbs != 1)
{
- int added = ((sizeof (int32_t) + 1 + 1 + __alignof__ (int32_t) - 1)
- & ~(__alignof__ (int32_t) - 1));
+ int added = ((sizeof (int32_t) + 1 + 1 + sizeof (int32_t) - 1)
+ & ~(sizeof (int32_t) - 1));
obstack_make_room (&extrapool, added);
obstack_int32_grow_fast (&extrapool, 0);
@@ -2333,13 +2333,13 @@ collate_output (struct localedef_t *locale, const struct charmap_t *charmap,
/* Add alignment bytes if necessary. */
while ((obstack_object_size (&extrapool)
- & (__alignof__ (int32_t) - 1)) != 0)
+ & (sizeof (int32_t) - 1)) != 0)
obstack_1grow_fast (&extrapool, '\0');
}
}
/* Add padding to the tables if necessary. */
- while ((obstack_object_size (&weightpool) & (__alignof__ (int32_t) - 1))
+ while ((obstack_object_size (&weightpool) & (sizeof (int32_t) - 1))
!= 0)
obstack_1grow (&weightpool, 0);
diff --git a/locale/weight.h b/locale/weight.h
index 645eda2..4a7ec32 100644
--- a/locale/weight.h
+++ b/locale/weight.h
@@ -69,8 +69,8 @@ findidx (const unsigned char **cpp, size_t len)
/* Up to the next entry. */
cp += nhere;
- if ((1 + nhere) % __alignof__ (int32_t) != 0)
- cp += __alignof__ (int32_t) - (1 + nhere) % __alignof__ (int32_t);
+ if ((1 + nhere) % sizeof (int32_t) != 0)
+ cp += sizeof (int32_t) - (1 + nhere) % sizeof (int32_t);
}
else
{
@@ -89,9 +89,9 @@ findidx (const unsigned char **cpp, size_t len)
{
/* Cannot be in this range. */
cp += 2 * nhere;
- if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
- cp += (__alignof__ (int32_t)
- - (1 + 2 * nhere) % __alignof__ (int32_t));
+ if ((1 + 2 * nhere) % sizeof (int32_t) != 0)
+ cp += (sizeof (int32_t)
+ - (1 + 2 * nhere) % sizeof (int32_t));
continue;
}
@@ -104,9 +104,9 @@ findidx (const unsigned char **cpp, size_t len)
{
/* Cannot be in this range. */
cp += 2 * nhere;
- if ((1 + 2 * nhere) % __alignof__ (int32_t) != 0)
- cp += (__alignof__ (int32_t)
- - (1 + 2 * nhere) % __alignof__ (int32_t));
+ if ((1 + 2 * nhere) % sizeof (int32_t) != 0)
+ cp += (sizeof (int32_t)
+ - (1 + 2 * nhere) % sizeof (int32_t));
continue;
}
--
Joseph S. Myers
joseph@codesourcery.com