From: Nick Clifton Date: Wed, 2 Oct 2019 10:57:16 +0000 (+0100) Subject: Change objcopy's --set-section-alignment option so that it takes a byte alignment... X-Git-Tag: binutils-2_33_1~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=146a3bb9cc78c459e63c23259d766b01c32df705;p=external%2Fbinutils.git Change objcopy's --set-section-alignment option so that it takes a byte alignment value rather than a power of two alignment value. PR 24942 * objcopy.c (copy_usage): Update description of --set-section-alignment. (copy_main): Interpret numeric argument of --set-section-alignment as a byte alignment, not a power of two alignment. * doc/binutils.texi: Update description of --set-section-alignment. * testsuite/binutils-all/set-section-alignment.d: New test. * testsuite/binutils-all/objcopy.exp: Run the new test. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index e817655..3babbb6 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,15 @@ +2019-10-02 Niklas Gürtler + + PR 24942 + * objcopy.c (copy_usage): Update description of + --set-section-alignment. + (copy_main): Interpret numeric argument of --set-section-alignment + as a byte alignment, not a power of two alignment. + * doc/binutils.texi: Update description of + --set-section-alignment. + * testsuite/binutils-all/set-section-alignment.d: New test. + * testsuite/binutils-all/objcopy.exp: Run the new test. + 2019-09-30 Phil Blundell Release 2.33 diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index bb37cb0..059d61c 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -1622,9 +1622,9 @@ contents--just remove the section instead. Not all flags are meaningful for all object file formats. @item --set-section-alignment @var{sectionpattern}=@var{align} -Set the alignment for any sections matching @var{sectionpattern}. @var{align} -specifies the alignment as the exponent for the power of two, i.e. the -alignment in bytes will be 2^@var{align}. +Set the alignment for any sections matching @var{sectionpattern}. +@var{align} specifies the alignment in bytes and must be a power of +two, i.e. 1, 2, 4, 8@dots{}. @item --add-section @var{sectionname}=@var{filename} Add a new section named @var{sectionname} while copying the file. The diff --git a/binutils/objcopy.c b/binutils/objcopy.c index b702e52..c05d456 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -615,7 +615,7 @@ copy_usage (FILE *stream, int exit_status) --set-section-flags =\n\ Set section 's properties to \n\ --set-section-alignment =\n\ - Set section 's alignment to 2^ bytes\n\ + Set section 's alignment to bytes\n\ --add-section = Add section found in to output\n\ --update-section =\n\ Update contents of section with\n\ @@ -5283,24 +5283,37 @@ copy_main (int argc, char *argv[]) const char *s; int len; char *name; - int align; + int palign, align; s = strchr (optarg, '='); if (s == NULL) - fatal (_("bad format for %s"), "--set-section-alignment"); + fatal (_("bad format for --set-section-alignment: argument needed")); - align = atoi(s+1); - if (align < 0) - fatal (_("bad format for %s"), "--set-section-alignment"); + align = atoi (s + 1); + if (align <= 0) + fatal (_("bad format for --set-section-alignment: numeric argument needed")); + /* Convert integer alignment into a power-of-two alignment. */ + palign = 0; + while ((align & 1) == 0) + { + align >>= 1; + ++palign; + } + + if (align != 1) + /* Number has more than on 1, i.e. wasn't a power of 2. */ + fatal (_("bad format for --set-section-alignment: alignment is not a power of two")); + + /* Add the alignment setting to the section list. */ len = s - optarg; name = (char *) xmalloc (len + 1); strncpy (name, optarg, len); name[len] = '\0'; p = find_section_list (name, TRUE, SECTION_CONTEXT_SET_ALIGNMENT); - - p->alignment = align; + if (p) + p->alignment = palign; } break; diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp index 3e3c355..e12a828 100644 --- a/binutils/testsuite/binutils-all/objcopy.exp +++ b/binutils/testsuite/binutils-all/objcopy.exp @@ -1310,3 +1310,5 @@ proc objcopy_remove_relocations_from_executable { } { objcopy_remove_relocations_from_executable run_dump_test "pr23633" + +run_dump_test "set-section-alignment" diff --git a/binutils/testsuite/binutils-all/set-section-alignment.d b/binutils/testsuite/binutils-all/set-section-alignment.d new file mode 100644 index 0000000..d562ce1 --- /dev/null +++ b/binutils/testsuite/binutils-all/set-section-alignment.d @@ -0,0 +1,9 @@ +#source: pr23633.s +#PROG: objcopy +#objcopy: --set-section-alignment .text=16 +#objdump: --section-headers +#notarget: *-*-*aout *-*-*coff *-*-cygwin* *-*-darwin *-*-mingw* *-*-go32 *-*-*pe hppa*-*-hpux* ns32k-*-* powerpc-*-aix* rs6000-*-* rx-*-* *-*-vms + +#... +.*\.text.*2\*\*4 +#pass