[Bug binutils/24942] New: objcopy: Add option for setting section alignment
https://sourceware.org/bugzilla/show_bug.cgi?id=24942 Bug ID: 24942 Summary: objcopy: Add option for setting section alignment Product: binutils Version: 2.33 (HEAD) Status: UNCONFIRMED Severity: enhancement Priority: P2 Component: binutils Assignee: unassigned at sourceware dot org Reporter: profclonk at gmail dot com Target Milestone: --- Created attachment 11965 --> https://sourceware.org/bugzilla/attachment.cgi?id=11965&action=edit Patch for adding --set-section-alignment When using the old trick¹ of using objcopy to convert arbitrary binary files into ELF (".o") files for including e.g. pictures or fonts into program memory, objcopy currently always sets the alignment of the produced ELF section to "1". When linking this file, the contained binary data can end up at an address that is not properly aligned, which might render it inaccessible for word-wise access or even DMA (on embedded targets). Therefore, I would like to propose adding a command line option to objcopy to set the alignment of the produced section. Please see the attached git patch file for a possible implementation. It adds an option "--set-section-alignment =" that works much like "--set-section-flags", but expects a simple integer as "". The specified alignment will override the alignment of the input section (if any). Could this be included in the official binutils code? 1: https://mcuoneclipse.com/2018/01/27/converting-a-raw-binary-file-into-an-elf-dwarf-file-for-loading-and-debugging/ -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/24942] objcopy: Add option for setting section alignment
https://sourceware.org/bugzilla/show_bug.cgi?id=24942 --- Comment #2 from Niklas Gürtler --- Hi Nick, I knew about "incbin" but needing an (additional) assembly file seems somewhat clunky. There are even more possibilities: Putting each converted .o file into its own section, and aligning those sections via the final linker script. Hacking together a tool that modifies the alignment field in the ELF header. It might even be possible to do a partial linking step to set the alignment of a objcopy-produced .o-file using a linker script. However, if objcopy is capable of converting binary to ELF, then why not make it actually useful by setting the alignment requirement, especially since it's a rather simple fix? This would allow us to produce the desired .o file with one simple step. Greetings, Niklas -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/24942] objcopy: Add option for setting section alignment
https://sourceware.org/bugzilla/show_bug.cgi?id=24942 --- Comment #5 from Niklas Gürtler --- Hi Nick, awesome, thank you! Now just to wait for the release... :) Have a nice day, Niklas -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/24942] objcopy: Add option for setting section alignment
https://sourceware.org/bugzilla/show_bug.cgi?id=24942 --- Comment #8 from Niklas Gürtler --- I think not all BFD targets support arbitrary alignment, some may only support powers of 2. The internal representation in the BFD library stores only the exponent, so there would have to be a conversion (i.e. log2), with additional potential for errors, so I think it's best to have the user do that and document it properly. The ".align" directive also works this way (at least on ARM). When using --rename-section, the original section name would need to be specified for --set-section-alignment, just like with --set-section-flags. -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils
[Bug binutils/24942] objcopy: Add option for setting section alignment
https://sourceware.org/bugzilla/show_bug.cgi?id=24942 --- Comment #11 from Niklas Gürtler --- Created attachment 12002 --> https://sourceware.org/bugzilla/attachment.cgi?id=12002&action=edit Patch for specifying powers of two instead of exponents Okay, here is a patch for specifying the alignment as a power of two instead of an exponent. I don't like it very much however... -- You are receiving this mail because: You are on the CC list for the bug. ___ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils