symbols: don't over-align data
PATCH 1/1 symbols: don't over-align data
Arrays of .byte or .short don't really need aligning better than 1 or 2 bytes respectively. Arrays of .long also don't need aligning to 8 bytes (which would have happened when BITS_PER_LONG is 64 and SYMBOLS_ORIGIN is not defined).
---
Strictly speaking, however, we may have been under-aligning the arrays for
x86-64: The psABI mandates
"An array uses the same alignment as its elements, except that a local or
global array variable of length at least 16 bytes or a C99 variable- length array variable always has alignment of at least 16 bytes."
I don't think the compiler can leverage that though, as long as we declare the arrays as incomplete ones (without dimension). Note the subtlety
though: C99 distinguishes [] and [*] (only the latter being "variable length"), while the psABI may not mean to limit its constraint to the latter form.
This, contextually (not functionally), goes on top of "symbols: check table sizes don't change between linking passes 2 and 3"
xen/tools/symbols.c +13 -13
@@ -252,7 +252,7 @@ static void read_map(FILE *in) } } -static void output_label (const char *label,bool keep) +static void output_label (const char *label,const char *align,bool keep) {static bool pending;
@@ -266,10 +266,10 @@ static void output_label(const char *labreturn ;if (symbol_prefix_char) { -printf ("DATA(%c%s, ALGN)\n" , symbol_prefix_char, label); +printf ("DATA(%c%s, %s)\n" , symbol_prefix_char, label, align);printf ("#define CURRENT %c%s\n" , symbol_prefix_char, label); }else { -printf ("DATA(%s, ALGN)\n" , label); +printf ("DATA(%s, %s)\n" , label, align);printf ("#define CURRENT %s\n" , label); } }
@@ -353,9 +353,9 @@ static void write_src(void)printf ("#ifndef SYMBOLS_ORIGIN\n" );printf ("#define SYMBOLS_ORIGIN 0\n" ); -output_label ("symbols_addresses" , false); +output_label ("symbols_addresses" ,"ALGN" , false);printf ("#else\n" ); -output_label ("symbols_offsets" , true); +output_label ("symbols_offsets" ,"ALGN" , true);printf ("#endif\n" );for (i =0 , ends =0 ; i < table_cnt; i++) {printf ("\tPTR\t%#llx - SYMBOLS_ORIGIN\n" , table[i].addr);
@@ -380,14 +380,14 @@ static void write_src(void) table[i].addr + table[i].size); } -output_label ("symbols_num_addrs" , false); +output_label ("symbols_num_addrs" ,"4" , false);printf ("\t.long\t%d\n" , table_cnt + ends);/* table of offset markers, that give the offset in the compressed stream * every 256 symbols */ markers =malloc (sizeof (*markers) * ((table_cnt + ends +255 ) >>8 )); -output_label ("symbols_names" , false); +output_label ("symbols_names" ,"1" , false);for (i =0 , off =0 , ends =0 ; i < table_cnt; i++) {if (((i + ends) &0xFF ) ==0 ) markers[(i + ends) >>8 ] = off;
@@ -412,11 +412,11 @@ static void write_src(void) ++off; } -output_label ("symbols_markers" , false); +output_label ("symbols_markers" ,"4" , false);for (i =0 ; i < ((table_cnt + ends +255 ) >>8 ); i++)printf ("\t.long\t%d\n" , markers[i]); -output_label ("symbols_token_table" , false); +output_label ("symbols_token_table" ,"1" , false); off =0 ;for (i =0 ; i <256 ; i++) { best_idx[i] = off;
@@ -425,12 +425,12 @@ static void write_src(void) off +=strlen (buf) +1 ; } -output_label ("symbols_token_index" , false); +output_label ("symbols_token_index" ,"2" , false);for (i =0 ; i <256 ; i++)printf ("\t.short\t%d\n" , best_idx[i]);if (sort_by_name) { -output_label ("symbols_num_names" , false); +output_label ("symbols_num_names" ,"4" , false);printf ("\t.long\t%d\n" , table_cnt);/* Sorted by original symbol names and type. */
@@ -439,12 +439,12 @@ static void write_src(void)/* A fixed sized array with two entries: offset in the * compressed stream (for symbol name), and offset in * symbols_addresses (or symbols_offset). */ -output_label ("symbols_sorted_offsets" , false); +output_label ("symbols_sorted_offsets" ,"4" , false);for (i =0 ; i < table_cnt; i++)printf ("\t.long %u, %u\n" , table[i].stream_offset, table[i].addr_idx); } -output_label (NULL , false); +output_label (NULL ,NULL , false);free (markers); }
Quoted 6 lines · Jan Beulich
Arrays of .byte or .short don't really need aligning better than 1 or 2 bytes respectively. Arrays of .long also don't need aligning to 8 bytes (which would have happened when
BITS_PER_LONGis 64 andSYMBOLS_ORIGINis not defined).Signed-off-by Jan Beulich <[email protected]>
Thanks, Roger.