Skip to content

Commit 725a19b

Browse files
committed
sframe: fix the defined SFRAME_FRE_TYPE_*_LIMIT constants
An earlier commit 3f10746 defined the SFRAME_FRE_TYPE_*_LIMIT constants. These constants are used (by gas and libsframe) to pick an SFrame FRE type based on the function size. Those constants, however, were buggy, causing the generated SFrame sections to be bloated as SFRAME_FRE_TYPE_ADDR2/SFRAME_FRE_TYPE_ADDR4 got chosen more often than necessary. gas/ * sframe-opt.c (sframe_estimate_size_before_relax): Use typecast. (sframe_convert_frag): Likewise. libsframe/ * sframe.c (sframe_calc_fre_type): Use a more appropriate type for argument. Adjust the check for SFRAME_FRE_TYPE_ADDR4_LIMIT to keep it warning-free but meaningful. include/ * sframe-api.h (sframe_calc_fre_type): Use a more appropriate type for the argument. * sframe.h (SFRAME_FRE_TYPE_ADDR1_LIMIT): Correct the constant. (SFRAME_FRE_TYPE_ADDR2_LIMIT): Likewise. (SFRAME_FRE_TYPE_ADDR4_LIMIT): Likewise.
1 parent cd9aea3 commit 725a19b

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

gas/sframe-opt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ sframe_estimate_size_before_relax (fragS *frag)
5353
widthS = exp->X_op_symbol;
5454
width = resolve_symbol_value (widthS);
5555

56-
if (width < SFRAME_FRE_TYPE_ADDR1_LIMIT)
56+
if (width < (offsetT) SFRAME_FRE_TYPE_ADDR1_LIMIT)
5757
ret = 1;
58-
else if (width < SFRAME_FRE_TYPE_ADDR2_LIMIT)
58+
else if (width < (offsetT) SFRAME_FRE_TYPE_ADDR2_LIMIT)
5959
ret = 2;
6060
else
6161
ret = 4;
@@ -123,9 +123,9 @@ sframe_convert_frag (fragS *frag)
123123
/* Calculate the applicable fre_type. */
124124
fsizeS = exp->X_op_symbol;
125125
fsize = resolve_symbol_value (fsizeS);
126-
if (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT)
126+
if (fsize < (offsetT) SFRAME_FRE_TYPE_ADDR1_LIMIT)
127127
fre_type = SFRAME_FRE_TYPE_ADDR1;
128-
else if (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT)
128+
else if (fsize < (offsetT) SFRAME_FRE_TYPE_ADDR2_LIMIT)
129129
fre_type = SFRAME_FRE_TYPE_ADDR2;
130130
else
131131
fre_type = SFRAME_FRE_TYPE_ADDR4;
@@ -150,11 +150,11 @@ sframe_convert_frag (fragS *frag)
150150
switch (frag->fr_subtype & 7)
151151
{
152152
case 1:
153-
gas_assert (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT);
153+
gas_assert (fsize < (offsetT) SFRAME_FRE_TYPE_ADDR1_LIMIT);
154154
frag->fr_literal[frag->fr_fix] = diff;
155155
break;
156156
case 2:
157-
gas_assert (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT);
157+
gas_assert (fsize < (offsetT) SFRAME_FRE_TYPE_ADDR2_LIMIT);
158158
md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2);
159159
break;
160160
case 4:

include/sframe-api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ sframe_fde_create_func_info (unsigned int fre_type, unsigned int fde_type);
9696
/* Gather the FRE type given the function size. */
9797

9898
extern unsigned int
99-
sframe_calc_fre_type (unsigned int func_size);
99+
sframe_calc_fre_type (size_t func_size);
100100

101101
/* The SFrame Decoder. */
102102

include/sframe.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ typedef struct sframe_frame_row_entry_addr1
304304

305305
/* Upper limit of start address in sframe_frame_row_entry_addr1
306306
is 0x100 (not inclusive). */
307-
#define SFRAME_FRE_TYPE_ADDR1_LIMIT ((SFRAME_FRE_TYPE_ADDR1 + 1) * 8)
307+
#define SFRAME_FRE_TYPE_ADDR1_LIMIT \
308+
(1ULL << ((SFRAME_FRE_TYPE_ADDR1 + 1) * 8))
308309

309310
/* Used when SFRAME_FRE_TYPE_ADDR2 is specified as FRE type. */
310311
typedef struct sframe_frame_row_entry_addr2
@@ -317,7 +318,8 @@ typedef struct sframe_frame_row_entry_addr2
317318

318319
/* Upper limit of start address in sframe_frame_row_entry_addr2
319320
is 0x10000 (not inclusive). */
320-
#define SFRAME_FRE_TYPE_ADDR2_LIMIT ((SFRAME_FRE_TYPE_ADDR2 * 2) * 8)
321+
#define SFRAME_FRE_TYPE_ADDR2_LIMIT \
322+
(1ULL << ((SFRAME_FRE_TYPE_ADDR2 * 2) * 8))
321323

322324
/* Used when SFRAME_FRE_TYPE_ADDR4 is specified as FRE type. */
323325
typedef struct sframe_frame_row_entry_addr4
@@ -330,7 +332,8 @@ typedef struct sframe_frame_row_entry_addr4
330332

331333
/* Upper limit of start address in sframe_frame_row_entry_addr2
332334
is 0x100000000 (not inclusive). */
333-
#define SFRAME_FRE_TYPE_ADDR4_LIMIT ((SFRAME_FRE_TYPE_ADDR4 * 2) * 8)
335+
#define SFRAME_FRE_TYPE_ADDR4_LIMIT \
336+
(1ULL << ((SFRAME_FRE_TYPE_ADDR4 * 2) * 8))
334337

335338
#ifdef __cplusplus
336339
}

libsframe/sframe.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,16 @@ sframe_fde_create_func_info (unsigned int fre_type,
584584
/* FIXME API for linker. Revisit if its better placed somewhere else? */
585585

586586
unsigned int
587-
sframe_calc_fre_type (unsigned int func_size)
587+
sframe_calc_fre_type (size_t func_size)
588588
{
589589
unsigned int fre_type = 0;
590590
if (func_size < SFRAME_FRE_TYPE_ADDR1_LIMIT)
591591
fre_type = SFRAME_FRE_TYPE_ADDR1;
592592
else if (func_size < SFRAME_FRE_TYPE_ADDR2_LIMIT)
593593
fre_type = SFRAME_FRE_TYPE_ADDR2;
594-
else if (func_size < SFRAME_FRE_TYPE_ADDR4_LIMIT)
594+
/* Adjust the check a bit so that it remains warning-free but meaningful
595+
on 32-bit systems. */
596+
else if (func_size <= (size_t) (SFRAME_FRE_TYPE_ADDR4_LIMIT - 1))
595597
fre_type = SFRAME_FRE_TYPE_ADDR4;
596598
return fre_type;
597599
}

0 commit comments

Comments
 (0)