From: Nick Bowler Date: Fri, 23 Feb 2024 01:41:23 +0000 (-0500) Subject: libcdecl: Avoid overalignment of string tables. X-Git-Tag: v1.3~8 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/4c819e9466a0573afae0f9787a4704a479517624 libcdecl: Avoid overalignment of string tables. For whatever reason, on x86_64 gcc allocates any static array at least 32 bytes in size with 32 byte alignment. In the case of things like constant string tables, this ends up wasting a bunch of space for no obvious reason. Adding suitable _Alignas directives works to prevent overalignment. --- diff --git a/common b/common index cba6ab6..b6ec120 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit cba6ab66683d20b46def45f691fa7c750f3f9a2b +Subproject commit b6ec120435a070a28eafe0b3e686ef2ac9b0f042 diff --git a/configure.ac b/configure.ac index 8e4286b..4d9ad34 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,7 @@ AC_CHECK_TYPES([unsigned __int64]) AC_C_FLEXIBLE_ARRAY_MEMBER AC_C_INLINE DX_C_FOR_DECLARATIONS +DX_C_ALIGNAS AM_PROG_AR LT_INIT diff --git a/src/error.c b/src/error.c index eb85b89..e07a410 100644 --- a/src/error.c +++ b/src/error.c @@ -31,7 +31,7 @@ static struct cdecl_error err_no_mem; static void set_err(unsigned code, struct cdecl_error *err) { - static const char errmsgs[] = STRTAB_INITIALIZER; + static const char _Alignas(1) errmsgs[] = STRTAB_INITIALIZER; switch (code) { case CDECL__ENOMEM: diff --git a/src/gen-specstr.awk b/src/gen-specstr.awk index c9148f8..0bc8278 100755 --- a/src/gen-specstr.awk +++ b/src/gen-specstr.awk @@ -1,6 +1,6 @@ #!/bin/awk -f # -# Copyright © 2021, 2023 Nick Bowler +# Copyright © 2021, 2023-2024 Nick Bowler # # Generate a function to return the C keyword corresponding to a specifier # type as a string, for internal use by the output routines. @@ -82,7 +82,7 @@ END { print "static const char *spec_string(unsigned type)" print "{" - print "\tstatic const uint_least8_t idx[] = {"; + print "\tstatic const unsigned char _Alignas(1) idx[] = {"; print "\t\t" offset_table; print "\t};\n";