This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold] Merging string literals with bigger alignment
- From: Cary Coutant <ccoutant at google dot com>
- To: Alexander Ivchenko <aivchenk at gmail dot com>
- Cc: Ian Lance Taylor <iant at google dot com>, binutils <binutils at sourceware dot org>, Sriraman Tallam <tmsriram at google dot com>
- Date: Thu, 28 Mar 2013 11:17:53 -0700
- Subject: Re: [gold] Merging string literals with bigger alignment
- References: <CACysShhXDPxUsqdUprwhyGcaNiS9X_ODbrW847wHHiwbUh4LhA at mail dot gmail dot com> <CAKOQZ8xROxuJMD19P7JoM084LDyDKk_anwiuoWRpS+2MLeThnA at mail dot gmail dot com> <CACysShhaCv68A39oTk5FfmsdRFjhoOjQEzEZys4U0-sZs-x+4A at mail dot gmail dot com> <CAKOQZ8ypF=yCMmrwn-8jSp_WBMdrNi6NqwJRqabG7ZUwV2yMhg at mail dot gmail dot com> <CACysShhyE2G_8fz1pLSjTdJ_f9OYdSHHB9zvydWPaJNHjFkQ8g at mail dot gmail dot com> <CAKOQZ8wd_7bfSfMsm_WmJnSdT_J4qF-JM+3Ex=tU0iDJCOWETQ at mail dot gmail dot com> <CACysShh22grCuoa7-b3QV7D_Q-RBYrtLH8ifr2yRcS93+GRk1g at mail dot gmail dot com> <CAHACq4pqmPp7JqwOJ_Ux0NN7yVZzq82t4uf9ZUKTa8eXL+Znrg at mail dot gmail dot com> <CACysShjRoZMEp=JasvdY9Jg=+ab15FEEUY-WnR-4dLb9q+C-Cg at mail dot gmail dot com> <CAHACq4rEinAxU_5Cp7SQiNeZN8tZsbp-YCwbuzR-bC5Z9GOrJw at mail dot gmail dot com> <CACysShh_8waYTA4tQWGnRER5xrwv=NgSn2NRhzOLfncPuOeOsg at mail dot gmail dot com>
+ // We assume here that the beginning of the section is correctly
+ // aligned, so each string within the section must retain the same
+ // modulo.
+ uint64_t init_align_modulo = (uint64_t) pdata % this->addralign();
The view you're looking at will already be aligned correctly, so I
don't think this is necessary (i.e., init_align_modulo will always be
0).
+ if ((uint64_t) p % this->addralign() != init_align_modulo)
+ gold_warning(_("string %s is incorrectly aligned within"
+ " the section %s. Its alignment won't be preserved"),
+ (unsigned char*)p,
+ object->section_name(shndx).c_str());
If Char_type is not char, printing (unsigned char*)p with %s will not
work. Also, this cast should use reinterpret_cast<...>(p) instead of
the C-style cast.
I think you'll also need to change
Stringpool_template<Stringpool_char>::Stringpool_eq::operator() to
check the alignment that you've stored in the Hashkey. Imagine one
section that adds a string with alignment 1, and a subsequent section
that adds the same string with alignment 4 -- when adding the string
the second time, you'll match the first, and keep the 1-byte
alignment. Ideally, you'd just update the alignment so there's only
one copy of the string at the larger alignment, but that will only
work if you're optimizing the string tables (-O2).
-cary