[patch, avr] Support .gnu_attribute 4 (Tag_GNU_AVR_VTABLE_AS) for vtable address spaces
Georg-Johann Lay
avr@gjlay.de
Wed Jun 10 19:14:38 GMT 2026
The expected, upcoming support for ISO/IEC TR 18037 "Embedded C"
named address spaces in G++ would allow to put C++ virtual tables
into such address spaces, see https://gcc.gnu.org/PR69549
Currently, vtables are in the generic address space, which wastes
RAM on cores that locate .rodata in RAM.
Any change of vtables' address space is an ABI change, and
therefore it would be nice to have a feature that checks that
all object files linked into an app are using the same vtable AS.
The patch below introduces .gnu_attribute 4 (Tag_GNU_AVR_VTABLE_AS).
This mail is a request for a pre-approval of the patch.
I don't intend to apply it until it is clear that it's really
of any use and not dead code. Sadly, PR69549 is only progressing
at a glacial pace, so it may take yet another 10 year before
G++ can handle named address spaces --- or it may never learn it.
The patch is for trunk.
Johann
--
AVR: Add support for .gnu_attribute 4 (Tag_GNU_AVR_VTABLE_AS).
The expected, upcoming support for ISO/IEC TR 18037 "Embedded C"
named address spaces in G++ would allow to put C++ virtual tables
into such address spaces, see https://gcc.gnu.org/PR69549
The current address space used for vtables is the generic one,
which means that RAM is wasted on machines where .rodata is
located in RAM.
Named address spaces in G++ would allow users to chose an address space
that suits their requirements, e.g. by means of a new command-line
option and hooks like TARGET_ADDR_SPACE_FOR_ARTIFICIAL_RODATA.
However, in contrast to current user-selectable address spaces,
placing vtables in a different address space is an ABI change,
so that a means to detect ABI violations is highly appreciated.
The feature of choice is .gnu_attribute 4 (Tag_GNU_AVR_VTABLE_AS)
which would tag an object file with one of the following values:
0 (Val_GNU_AVR_VTABLE_NONE) for files that neither define nor access
vtables.
1 (Val_GNU_AVR_VTABLE_RAM) for files that use the generic address space.
2 (Val_GNU_AVR_VTABLE_FLASH) the file uses the 16-bit address space __flash.
3 (Val_GNU_AVR_VTABLE_FLASH1) the file uses the 16-bit address space
__flash1.
4 (Val_GNU_AVR_VTABLE_FLASH2) the file uses the 16-bit address space
__flash2.
5 (Val_GNU_AVR_VTABLE_FLASH3) the file uses the 16-bit address space
__flash3.
6 (Val_GNU_AVR_VTABLE_FLASH4) the file uses the 16-bit address space
__flash4.
7 (Val_GNU_AVR_VTABLE_FLASH5) the file uses the 16-bit address space
__flash5.
8 (Val_GNU_AVR_VTABLE_FLASHX) the file uses the 24-bit address space
__flashx.
- A tag value of zero is compatible with all other tag values.
- Two non-zero tag values are compatible iff they are the same.
include/
* elf/avr.h (libiberty.h): Include for ARRAY_SIZE.
(Tag_GNU_AVR_VTABLE_AS = 4): New enum.
(Val_GNU_AVR_VTABLE_NONE, Val_GNU_AVR_VTABLE_RAM)
(Val_GNU_AVR_VTABLE_FLASH, Val_GNU_AVR_VTABLE_FLASH1)
(Val_GNU_AVR_VTABLE_FLASH2, Val_GNU_AVR_VTABLE_FLASH3)
(Val_GNU_AVR_VTABLE_FLASH4, Val_GNU_AVR_VTABLE_FLASH5)
(Val_GNU_AVR_VTABLE_FLASHX, Val_GNU_AVR_VTABLE_Sentinel): New
enum values for Tag_GNU_AVR_VTABLE_AS.
(avr_tag_vtable_as_name): New static function.
bfd/
* elf32-avr.h (bfd_avr_elf_merge_private_bfd_data): New proto.
* elf32-avr.c (libiberty.h): Include for ARRAY_SIZE.
(avr_elf_merge_obj_attributes): New static function.
(bfd_avr_elf_merge_private_bfd_data): New function that calls it.
(bfd_elf32_bfd_merge_private_bfd_data): Define to
bfd_avr_elf_merge_private_bfd_data.
gas/
* doc/as.texi (GNU Object Attributes) [AVR Attributes]: New subsection.
* config/tc-avr.h (avr_md_finish): New proto.
(md_finish): Define to avr_md_finish.
* config/tc-avr.c (avr_md_finish): New function to
sanity-check Tag_GNU_AVR_VTABLE_AS.
ld/
* testsuite/ld-avr/attr-gnu-4-1.s: New source.
* testsuite/ld-avr/attr-gnu-4-2.s: New source.
* testsuite/ld-avr/attr-gnu-4-1.d: New test.
* testsuite/ld-avr/attr-gnu-4-2.d: New test.
* testsuite/ld-avr/attr-gnu-4-1_2.d: New test.
binutils/
* readelf.c (display_avr_gnu_attribute): New static function.
(process_arch_specific) <EM_AVR>: Call process_attributes
with display_avr_gnu_attribute as a callback.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: binutils-attr-gnu-vtable-as.diff
Type: text/x-patch
Size: 10944 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20260610/18a12ad2/attachment-0001.bin>
More information about the Binutils
mailing list