From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7850) id 706033846989; Fri, 9 Dec 2022 18:27:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 706033846989 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670610468; bh=ujN+PMaSNGzYB3AzYPaVTkLQXZjqYG7YCoaTHzwQTXY=; h=From:To:Subject:Date:From; b=CawMAHmVP3ZhiHnGrMRPywMWuhXbYyon+/zYBGv0M1wvNgsSyhSJsEOst7V/BXpNk nScDnISBQv6DKrzpHCWo6TOoY+VwHrlboxTk7q2hBjb+hdi2wSlZvd5Dd63/kf+qXR zWSacI1BFZJEJOx/8uoE2gFpGoQ2WTgS7i22Vh18= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Indu Bhagat To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] sframe: gas: libsframe: define constants and remove magic numbers X-Act-Checkin: binutils-gdb X-Git-Author: Indu Bhagat X-Git-Refname: refs/heads/master X-Git-Oldrev: 70cfae61f4ed5db02d8daa59dc4432ff2d9302bd X-Git-Newrev: 3f107464e35cf63a529358a1c240821b30c35d2b Message-Id: <20221209182748.706033846989@sourceware.org> Date: Fri, 9 Dec 2022 18:27:48 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3f107464e35c= f63a529358a1c240821b30c35d2b commit 3f107464e35cf63a529358a1c240821b30c35d2b Author: Indu Bhagat Date: Fri Dec 9 10:23:07 2022 -0800 sframe: gas: libsframe: define constants and remove magic numbers =20 Define constants in sframe.h for the various limits associated with the range of offsets that can be encoded in the start address of an SFrame FRE. E.g., sframe_frame_row_entry_addr1 is used when start address offset can be encoded as 1-byte unsigned value. =20 Update the code in gas to use these defined constants as it checks for these limits, and remove the usage of magic numbers. =20 ChangeLog: =20 * gas/sframe-opt.c (sframe_estimate_size_before_relax): (sframe_convert_frag): Do not use magic numbers. * libsframe/sframe.c (sframe_calc_fre_type): Likewise. =20 include/ChangeLog: =20 * sframe.h (SFRAME_FRE_TYPE_ADDR1_LIMIT): New constant. (SFRAME_FRE_TYPE_ADDR2_LIMIT): Likewise. (SFRAME_FRE_TYPE_ADDR4_LIMIT): Likewise. Diff: --- gas/sframe-opt.c | 12 ++++++------ include/sframe.h | 15 +++++++++++++++ libsframe/sframe.c | 6 +++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gas/sframe-opt.c b/gas/sframe-opt.c index c17fd6b8332..6901aa82a77 100644 --- a/gas/sframe-opt.c +++ b/gas/sframe-opt.c @@ -53,9 +53,9 @@ sframe_estimate_size_before_relax (fragS *frag) widthS =3D exp->X_op_symbol; width =3D resolve_symbol_value (widthS); =20 - if (width < 0x100) + if (width < SFRAME_FRE_TYPE_ADDR1_LIMIT) ret =3D 1; - else if (width < 0x10000) + else if (width < SFRAME_FRE_TYPE_ADDR2_LIMIT) ret =3D 2; else ret =3D 4; @@ -109,9 +109,9 @@ sframe_convert_frag (fragS *frag) { fsizeS =3D frag->fr_symbol; fsize =3D resolve_symbol_value (fsizeS); - if (fsize < 0x100) + if (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT) func_info =3D SFRAME_FRE_TYPE_ADDR1; - else if (fsize < 0x10000) + else if (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT) func_info =3D SFRAME_FRE_TYPE_ADDR2; else func_info =3D SFRAME_FRE_TYPE_ADDR4; @@ -133,11 +133,11 @@ sframe_convert_frag (fragS *frag) switch (frag->fr_subtype & 7) { case 1: - gas_assert (fsize < 0x100); + gas_assert (fsize < SFRAME_FRE_TYPE_ADDR1_LIMIT); frag->fr_literal[frag->fr_fix] =3D diff; break; case 2: - gas_assert (fsize < 0x10000); + gas_assert (fsize < SFRAME_FRE_TYPE_ADDR2_LIMIT); md_number_to_chars (frag->fr_literal + frag->fr_fix, diff, 2); break; case 4: diff --git a/include/sframe.h b/include/sframe.h index 7e167bf4dbe..03a2d75dfd3 100644 --- a/include/sframe.h +++ b/include/sframe.h @@ -273,6 +273,7 @@ typedef struct sframe_fre_info fi */ =20 +/* Used when SFRAME_FRE_TYPE_ADDR1 is specified as FRE type. */ typedef struct sframe_frame_row_entry_addr1 { /* Start address of the frame row entry. Encoded as an 1-byte unsigned @@ -281,6 +282,11 @@ typedef struct sframe_frame_row_entry_addr1 sframe_fre_info sfre_info; } ATTRIBUTE_PACKED sframe_frame_row_entry_addr1; =20 +/* Upper limit of start address in sframe_frame_row_entry_addr1 + is 0x100 (not inclusive). */ +#define SFRAME_FRE_TYPE_ADDR1_LIMIT ((SFRAME_FRE_TYPE_ADDR1 + 1) * 8) + +/* Used when SFRAME_FRE_TYPE_ADDR2 is specified as FRE type. */ typedef struct sframe_frame_row_entry_addr2 { /* Start address of the frame row entry. Encoded as an 2-byte unsigned @@ -289,6 +295,11 @@ typedef struct sframe_frame_row_entry_addr2 sframe_fre_info sfre_info; } ATTRIBUTE_PACKED sframe_frame_row_entry_addr2; =20 +/* Upper limit of start address in sframe_frame_row_entry_addr2 + is 0x10000 (not inclusive). */ +#define SFRAME_FRE_TYPE_ADDR2_LIMIT ((SFRAME_FRE_TYPE_ADDR2 * 2) * 8) + +/* Used when SFRAME_FRE_TYPE_ADDR4 is specified as FRE type. */ typedef struct sframe_frame_row_entry_addr4 { /* Start address of the frame row entry. Encoded as a 4-byte unsigned @@ -297,6 +308,10 @@ typedef struct sframe_frame_row_entry_addr4 sframe_fre_info sfre_info; } ATTRIBUTE_PACKED sframe_frame_row_entry_addr4; =20 +/* Upper limit of start address in sframe_frame_row_entry_addr2 + is 0x100000000 (not inclusive). */ +#define SFRAME_FRE_TYPE_ADDR4_LIMIT ((SFRAME_FRE_TYPE_ADDR4 * 2) * 8) + #ifdef __cplusplus } #endif diff --git a/libsframe/sframe.c b/libsframe/sframe.c index 6e0eb7b6511..64fa9078d62 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -572,11 +572,11 @@ unsigned int sframe_calc_fre_type (unsigned int func_size) { unsigned int fre_type =3D 0; - if (func_size <=3D 0xff) + if (func_size < SFRAME_FRE_TYPE_ADDR1_LIMIT) fre_type =3D SFRAME_FRE_TYPE_ADDR1; - else if (func_size <=3D 0xffff) + else if (func_size < SFRAME_FRE_TYPE_ADDR2_LIMIT) fre_type =3D SFRAME_FRE_TYPE_ADDR2; - else if (func_size <=3D 0xffffffff) + else if (func_size < SFRAME_FRE_TYPE_ADDR4_LIMIT) fre_type =3D SFRAME_FRE_TYPE_ADDR4; return fre_type; }