aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2019-10-02 11:55:02 +0100
committerNick Clifton <nickc@redhat.com>2019-10-02 11:55:02 +0100
commitde4859eacb74a440d9fd61e4a0f051e3737a05dd (patch)
treeaf63b3781d3bf350958b4ee7f407ebd805dec414 /binutils/objcopy.c
parentc292080e11976e05603af9a91a67b052c33b56e3 (diff)
downloadgdb-de4859eacb74a440d9fd61e4a0f051e3737a05dd.zip
gdb-de4859eacb74a440d9fd61e4a0f051e3737a05dd.tar.gz
gdb-de4859eacb74a440d9fd61e4a0f051e3737a05dd.tar.bz2
Change objcopy's --set-section-alignment option to take 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.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 6489fbe..8f74beb 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -615,7 +615,7 @@ copy_usage (FILE *stream, int exit_status)
--set-section-flags <name>=<flags>\n\
Set section <name>'s properties to <flags>\n\
--set-section-alignment <name>=<align>\n\
- Set section <name>'s alignment to 2^<align> bytes\n\
+ Set section <name>'s alignment to <align> bytes\n\
--add-section <name>=<file> Add section <name> found in <file> to output\n\
--update-section <name>=<file>\n\
Update contents of section <name> with\n\
@@ -5280,24 +5280,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;