]> git.draconx.ca Git - cdecl99.git/commitdiff
libcdecl: Avoid overalignment of string tables.
authorNick Bowler <nbowler@draconx.ca>
Fri, 23 Feb 2024 01:41:23 +0000 (20:41 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 23 Feb 2024 01:46:29 +0000 (20:46 -0500)
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.

common
configure.ac
src/error.c
src/gen-specstr.awk

diff --git a/common b/common
index cba6ab66683d20b46def45f691fa7c750f3f9a2b..b6ec120435a070a28eafe0b3e686ef2ac9b0f042 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit cba6ab66683d20b46def45f691fa7c750f3f9a2b
+Subproject commit b6ec120435a070a28eafe0b3e686ef2ac9b0f042
index 8e4286b7cb49c1b9dba01c7a60e67d48d0a9b87d..4d9ad34a84ccc370ea0ad7b304bbb93721abaa5c 100644 (file)
@@ -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
index eb85b89c1bcbb4b015a0c36a9df33922da31d025..e07a410f66abd8b460771eb5de11b6e6229cd622 100644 (file)
@@ -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:
index c9148f80c22a95efbfed807fb063f52da9f463f0..0bc8278db172bbd7d2c782244639293c6bc8a3ed 100755 (executable)
@@ -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";