When the DM registers were added, sorting of the table was broken. With
the present arrangement, this leads to (only) %dm0 not being found by the
binary search that both use sites of the table entertain.
MIPS R5900 does not feature ceil/floor/round instructions, but only
ceil is correctly excluded at the moment. Correct the other two.
Signed-off-by: David Guillen Fandos <david@davidgf.net>
aarch64-pe +FAIL: gas/aarch64/fix-adj
arm-pe +FAIL: MVE vmlas instructions
arm-wince-pe +FAIL: MVE vmlas instructions
These new tests use ELF directives.
* testsuite/gas/aarch64/fix-adj.d: Only run on ELF targets.
* testsuite/gas/arm/mve-vmlas.d: Likewise.
Continuation of fix to VMLA
Bit 12 of the first halfword in the VMLAS instruction is listed as (0)
in the ARMARM (document DDI0553B.w, version ID07072023).
This means that the instruction does not discriminate between signed
and unsigned types and processing elements do not use the bit.
The encoding used by gas was based on an older version
of the document that made the sign important.
This change makes it possible to use vmlas.i8 (16,32) in addition to
vmlas.u8 and vmlas.s8 mnemonics, with the i8, i16 and i32 aliases becoming
the default when disassembling.
The generated encoding sets bit 12 to 0, compatibly with other
assembler implementations.
This patch adds support for MLB invalidate (MLBI) instruction.
Syntax: MLBI <mlbi_op>{, <Xt>}
This instruction is an alias to "SYS #4, C7, C0, #<op2>{, <Xt>}"
and MLBI being the preferred disassembly.
The following list of MLBI operations are supported in this patch for the
MLBI instructions enabled by "+mpamv2"
* alle1
* vmalle1
* vpide1
* vpmge1
On s390 64-bit (s390x) compilers may save the SP, FP, and RA registers,
which are of interest in SFrame, in other registers, such as floating-
point registers, for instance when in a leaf function.
SFrame does not explicitly track the SP. Instead SFrame relies on the
architecture-specific CFA definition to recover the SP. The s390x ELF
ABI [1] defines the CFA as SP at call site + 160, which results in the
implicit SP recovery rule SP = CFA - 160.
Assuming that CFI on s390 64-bit (s390x) adheres to the CFA definition,
it is safe to ignore any CFI directives, that specify the SP register at
entry to be saved either on the stack or in another register, as the SP
can then always be recovered using the implicit SP recovery rule.
[1]: s390x ELF ABI, https://github.com/IBM/s390x-abi/releases
Committed-by: Indu Bhagat <indu.bhagat@oracle.com>
gas/
* gen-sframe.c (sframe_xlate_do_register): Ignore .cfi_register SP
on s390x.
gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp (cfi-sframe-s390x-err-4): Rename
test to cfi-sframe-s390x-sp-register.
* gas/cfi-sframe/cfi-sframe-s390x-err-4.d: Rename to ...
* gas/cfi-sframe/cfi-sframe-s390x-err-4.s: Likewise.
* gas/cfi-sframe/cfi-sframe-s390x-sp-register.d: This. Test
that .cfi_register SP is ignored.
* gas/cfi-sframe/cfi-sframe-s390x-sp-register.s: Likewise. Add
minimal assembler sample.
This commit amalgamates a patch set proposed by Jens Remus to enable the
SFrame Version 3 Flexible FDE Type (SFRAME_FDE_TYPE_FLEX) generation for
the s390x ABI.
Previously, s390x relied on architecture-specific encoding (shifting register
numbers into offset fields) to represent register recovery rules. This limited
the complexity of CFI that could be supported. With Flex FDE enabled:
- s390x can now represent .cfi_def_cfa using non-SP/FP registers.
- The architecture-specific function s390_sframe_xlate_do_register () in GAS
is replaced by the generic Flex FDE generation path.
- The SFrame V3 specific macros for s390x register encoding are removed
from libsframe/include, as the generic Flex FDE format handles explicit
register columns natively.
The testsuite is updated to replace negative tests (which asserted
warnings or empty SFrame generation for these patterns) with positive
tests verifying valid Flex FDE generation.
Co-authored-by: Jens Remus <jremus@linux.ibm.com>
gas/
* config/tc-s390.c (s390_support_flex_fde_p): Return true to
enable Flex FDE generation.
* gen-sframe.c (s390_sframe_xlate_do_register): Disable s390x
specific implementation.
(sframe_xlate_do_register): Invoke generic Flex FDE path now
that flex FDE generation is supported.
gas/testsuite/
* gas/cfi-sframe/cfi-sframe-s390x-err-1.d: Removed.
* gas/cfi-sframe/cfi-sframe-s390x-err-1.s: Moved to...
* gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-1.s: ...here.
* gas/cfi-sframe/cfi-sframe-s390x-err-2.d: Removed.
* gas/cfi-sframe/cfi-sframe-s390x-err-2.s: Moved to...
* gas/cfi-sframe/cfi-sframe-s390x-non-spfp-cfa-2.s: ...here.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-1.d: Update to
expect Flex FDE output.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-2.d: Likewise.
* gas/cfi-sframe/cfi-sframe.exp: Run renamed tests.
include/
* sframe.h (SFRAME_V3_S390X_OFFSET_IS_REGNUM): Remove.
(SFRAME_V3_S390X_OFFSET_ENCODE_REGNUM): Remove.
(SFRAME_V3_S390X_OFFSET_DECODE_REGNUM): Remove.
libsframe/
* sframe-dump.c (sframe_s390x_offset_regnum_p): Return false
for SFrame V3.
(sframe_s390x_offset_decode_regnum): Remove V3 support.
This option will allow users to select emission of SFrame stack trace
information as per the SFrame version 3 specification. Currenly, SFrame
version 3 is also the default.
In future, as SFrame evolves, similar command line args may be added for
future versions.
gas/
* as.c (enum gen_sframe_version): New definition.
(parse_args): Add option processing for --gsframe-3.
* as.h (enum gen_sframe_version): New declaration.
* doc/as.texi: Document the new option.
* gen-sframe.c (sframe_set_version): Use enum gen_sframe_version
as version.
(output_sframe): Likewise.
gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: New test.
* gas/cfi-sframe/cfi-sframe-common-1d.d: Test new command line
option --gsframe-3.
* gas/cfi-sframe/cfi-sframe-common-1d.s: Likewise.
This patch introduces a structural change to the SFrame V3 format. It
shifts the SFrame Function Descriptor Entry (FDE) (a physical entity in
SFrame V2) into a conceptual one in SFrame V3, such that an FDE is now
split into two distinct parts to optimize the binary search table and
data organization:
- FDE Index (sframe_func_desc_idx_v3): This structure contains the
essential indexing information: the function start address offset,
function size in bytes, and the offset to the SFrame FDE
attribute/Frame Row Entries (FREs) area for the function.
- FDE Attributes (sframe_func_desc_attr_v3): The metadata regarding the
function (number and size of FREs, FDE type, and repetition block
size etc.) is moved to a new structure.
On-Disk Layout: In V3, the "Attributes" are now stored immediately
preceding the SFrame FREs for that function. The sfde_func_start_fre_off
now points to the attr structure, and the actual FREs follow immediately
after. IOW, the "Attributes" are now moved to the FRE sub-section,
located immediately preceding the FREs for the respective function.
The above layout has the advantage that:
a) its cleaner with separation between the index elements vs other data
b) the index has better cache locality (by virtue of it being smaller
than the layout in SFrame V2).
c) As the format evolves, the guarantees of alignment for FDE index
are easier to maintain. FDE attr, being in the SFrame FRE
sub-section, carry no guarantees of alignment.
This had been previously suggested and communicated in an earlier
discussion on binutils mailling list
https://inbox.sourceware.org/binutils/29b1f7b0-61ea-410c-8aca-d5dd6115e668@oracle.com/
The read/write paths in sframe.c are updated to account for this split.
sframe_fde_tbl_init now requires access to the FRE buffer to populate
the internal FDE table, as the attributes are no longer resident in the
FDE section.
flip_sframe is refactored into version-specific handlers (_v2 and _v3)
because the endian-swapping logic now differs significantly. In V3, the
iterator must jump from the FDE table to the FRE section to swap the
attributes.
Lastly, the two entities generating SFrame sections (GAS and GNU ld)
both now must _not_ set the sfde_func_start_fre_off to zero, when the
number of FREs is zero. This is because now there will be some valid
attr data at that location.
Backward Compatibility: Due to the need to support readelf/objdump for
SFrame V2 sections, the patch explicitly maintains V2 support via
separate code paths (e.g., flip_sframe_fdes_with_fres_v2)
Note about alignment: Now that the sframe_func_desc_idx_v3 is refactored
out of the conceptual SFrame FDE, SFrame FDE index member elements are
at aligned boundaries again. The alignment property for SFrame FDE was
broken from an ealier patch "[08/36] sframe: gas: libsframe: use
uint16_t for num_fres of FDE" up until this one.
include/
* sframe.h (sframe_func_desc_entry_v3): Remove sfde_func_num_fres,
sfde_func_info, sfde_func_info2, and sfde_func_rep_size. Rename
to sframe_func_desc_idx_v3.
(sframe_func_desc_attr_v3): New SFrame FDE attribute structure.
libsframe/
* sframe.c (sframe_fde_tbl_init): Add argument for FRE buffer.
Read attributes from the FRE section for V3.
(flip_fde_desc): Rename from flip_fde. Check size against
sframe_func_desc_entry_v3.
(flip_fde_attr_v3): New function.
(sframe_decode_fde_desc_v2): New function extracted from
sframe_decode_fde.
(sframe_decode_fde_desc_v3): New function.
(sframe_decode_fde_attr_v3): New function.
(flip_sframe_fdes_with_fres_v2): New function for V2 flipping.
(flip_sframe_fdes_with_fres_v3): New function for V3 flipping.
(flip_sframe): Dispatch to version-specific flip functions.
(sframe_decode): Pass FRE buffer to sframe_fde_tbl_init.
(sframe_decoder_get_offsetof_fde_start_addr): Adjust for subset
of sframe_func_desc_entry_v3 restructured into
sframe_func_desc_idx_v3.
(sframe_encoder_get_offsetof_fde_start_addr): Likewise.
(sframe_find_fre): Skip attribute size to find FREs in V3.
(sframe_decoder_get_fre): Likewise.
(sframe_decoder_get_fres_buf): Likewise.
(sframe_encoder_add_fre): Add attribute size to byte count.
(sframe_encoder_add_fres_buf): Read attributes from buffer.
(sframe_encoder_write_fde): Write only FDE index fields.
(sframe_encoder_write_func_attr): New function.
(sframe_encoder_write_sframe): Write FDE attributes before FREs.
gas/
* gen-sframe.c (output_sframe_funcdesc): Do not reset
sfde_func_start_fre_off to zero when zero num FREs.
(output_sframe_func_desc_attr): New refactored out function.
(output_sframe_internal): Invoke output_sframe_func_desc_attr.
libsframe/testsuite/
* libsframe.decode/DATA2: Regenerate data file.
With the introduction of flex FDE type, handling .cfi_offset for
RA needs adjustment.
On architectures like x86_64, the return address (RA) is typically saved
at a fixed offset from the CFA. Previous versions of the SFrame format
assumed this fixed offset was invariant for the entire function on such
architectures. Consequently, GAS would warn and suppress SFrame
generation if it encountered a .cfi_offset directive for the RA
register that deviated from this fixed default.
SFrame V3 introduces "Flex FDEs" which allows tracking the RA location
explicitly even on architectures where it is usually fixed.
This patch updates sframe_xlate_do_offset () to leverage Flex FDEs. When
processing a .cfi_offset for the RA register:
- The check for non-representable RA offsets is relaxed. If the ABI
supports Flex FDEs (SFrame V3), GAS proceeds instead of issuing a
warning.
- For ABIs without explicit RA tracking (like AMD64), if the RA
offset differs from the default fixed offset, the FDE is marked as a
Flex FDE, and the new stack location is recorded.
- Logic is added to detect when the RA is restored to its standard
fixed offset. In this case, the tracking state is reset (ra_loc set
to SFRAME_FRE_ELEM_LOC_NONE), deferring to the ABI's default fixed RA
offset behavior.
gas/
* gen-sframe.c (sframe_xlate_do_offset): Support .cfi_offset for RA
by switching to Flex FDEs when necessary.
gas/testsuite/
* gas/cfi-sframe/cfi-sframe-x86_64-6.d: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-6.s: New test to check
transition of location of REG_RA from register to CFA-8 (default
location on AMD64). Flex FDE in effect.
* gas/cfi-sframe/cfi-sframe.exp: Add new test.
SFrame does not track the SP. For recovery of the SP, SFrame relies on
the architecture/ABI's CFA definition:
CFA = SP [+ offset // on s390x]
Which results in the following implicit CFA value offset rule for SP:
SP = CFA [- offset // on s390x]
Where offset is zero for most architectures/ABIs, except s390x.
Therefore .cfi_register SP, reg directives must be rejected, as such
semantics cannot be represented in SFrame yet.
gas/
* gas/gen-sframe.c (s390_sframe_xlate_do_register): Check for
REG_SP and reject while generating a warning.
(sframe_xlate_do_register): Likewise.
gas/testsuite/
* gas/cfi-sframe/cfi-sframe-s390x-err-4.d: New test.
* gas/cfi-sframe/cfi-sframe-s390x-err-4.s: Likewise.
* gas/cfi-sframe/cfi-sframe-x86_64-empty-5.d: Likewise.
* gas/cfi-sframe/cfi-sframe-x86_64-empty-5.s: Likewise.
* gas/cfi-sframe/cfi-sframe.exp: Add new tests.
Use SFrame FDE of type SFRAME_FDE_TYPE_FLEX_TOPMOST_FRAME.
When FP, RA were moved to a general-purpose register, the SFrame
generation previously warned and skipped the FDE (except on s390x).
This patch updates the translator to detect .cfi_register for RA (and
FP), tracks the destination register in the SFrame row entry,
and emits the register in the relevant FRE offsets in SFrame FDE type
SFRAME_FDE_TYPE_FLEX.
gas/
* gen-sframe.c (sframe_row_entry_initialize): Propagate ra_reg
and ra_deref_p.
(sframe_xlate_do_register): Handle .cfi_register for RA/FP on
AMD64 by setting flex_p and recording the register.
gas/testsuite/gas/
* cfi-sframe/cfi-sframe.exp: Run new test.
* cfi-sframe/cfi-sframe-x86_64-5.d: New test.
* cfi-sframe/cfi-sframe-x86_64-5.s: Simple test for checking
FLEX FDE generation for `.cfi_register REG_RA, XX`.
* cfi-sframe/cfi-sframe-x86_64-esc-expr-3.d: New test.
* cfi-sframe/cfi-sframe-x86_64-esc-expr-3.s: New test with DWARF
expression for REG_FP, followed by .cfi_register and .cfi_offset
for REG_FP.
* cfi-sframe/cfi-sframe-x86_64-ra-undefined-flex-1.d: New test.
* cfi-sframe/cfi-sframe-x86_64-ra-undefined-flex-1.s: New test
for FLEX FDE with undefined RA.
gas/testsuite/
* gas/cfi-sframe/cfi-sframe-x86_64-4.d: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-4.s: Non SP/FP based CFA.
* gas/cfi-sframe/cfi-sframe-x86_64-esc-expr-1.d: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-esc-expr-1.s: DRAP pattern
with both CFA expression and FP expression.
* gas/cfi-sframe/cfi-sframe-x86_64-esc-expr-2.d: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-esc-expr-2.s: Test CFA
expression with sleb128.
* gas/cfi-sframe/cfi-sframe.exp: Add new tests.
This patch updates the SFrame generation in GAS to translate specific
.cfi_escape directives into the new SFrame V3 FDE type
SFRAME_FDE_TYPE_FLEX.
The primary goal is to support code patterns where:
- the Canonical Frame Address (CFA) is not defined by a simple offset
from the Stack Pointer (SP) or Frame Pointer (FP), or where the CFA
rule involves a dereference. Such patterns are generated by compilers
for stack realignment (e.g., DRAP on x86_64, or when mixing legacy
codes that keep 4-byte stack alignment with modern codes that keep
16-byte stack alignment for SSE compatibility).
- the Frame Pointer is not defined by a simple offset from the CFA,
but may even involve another register and/or dereferencing.
- the Return Address is not defined by a simple offset from the CFA,
but may even involve another register and/or dereferencing.
Support for non-SP/FP based CFA: Update sframe_xlate_do_def_cfa () and
sframe_xlate_do_def_cfa_register () to detect when a non-SP/FP register
is used for the CFA.
Support for CFA expressions: A vital part of supporting the
above-mentioned cases on AMD64 is support for CFA expressions. Add
sframe_xlate_do_escape_cfa_expr () to parse simple
DW_CFA_def_cfa_expression sequence in .cfi_escape.
Support for FP expressions: Update sframe_xlate_do_escape_expr () to
handle DW_CFA_expression involving DW_OP_breg6 (rbp) on AMD64,
allowing for tracking of the Frame Pointer when it is saved with a
dereference rule in the DRAP pattern.
The "support" for both CFA expressions and FP expressions is quite
minimal, and is tailored to the most commonly seen occurrences generated
by GCC for AMD64.
gas/
* gas/gen-sframe.c (output_sframe_row_entry_offsets):
(sframe_xlate_do_def_cfa): Handle non-SP/FP CFA registers by setting
flex_p for AMD64.
(sframe_xlate_do_def_cfa_register): Likewise.
(sframe_xlate_escape_sleb128_to_int64): New definition.
(sframe_xlate_do_escape_cfa_expr): New function to handle
DW_CFA_def_cfa_expression of specific shapes.
(sframe_xlate_do_escape_expr): Update to handle dereferenced FP rules.
(sframe_xlate_do_cfi_escape): Invoke sframe_xlate_do_escape_cfa_expr ().
(create_sframe_all): In case of error, but when signal frame is
also true, there cannot be a flex FDE.
For the newly added SFrame FDE type SFRAME_FDE_TYPE_FLEX, add a new
backend hook so that the respective ABI/arch can opt out of the
generation of SFRAME_FDE_TYPE_FLEX in GAS.
AArch64 is an example of an ABI for which SFrame is supported, but one
that does not need the flexible FDE representation for any of the
current usecases currently.
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
gas/
* config/tc-aarch64.c (aarch64_support_flex_fde_p): New
definition.
* config/tc-aarch64.h (aarch64_support_flex_fde_p): New
declaration.
(sframe_support_flex_fde_p): Define.
* config/tc-i386.c (x86_support_flex_fde_p): New definition.
* config/tc-i386.h (x86_support_flex_fde_p): New declaration.
(sframe_support_flex_fde_p): Define.
* config/tc-s390.c (s390_support_flex_fde_p): New definition.
* config/tc-s390.h (s390_support_flex_fde_p): New declaration.
(sframe_support_flex_fde_p): Define.
This patch updates the routines for emission of the new FDE type
SFRAME_FDE_TYPE_FLEX in the SFrame output section. The support for
generating these flex FDEs themselves is added in a subsequent commit.
Update struct sframe_row_entry to track additional state for CFA,
FP, and RA. Modify output_sframe_row_entry_offsets () to emit
metadata/offset pairs for flexible FDEs or padding where applicable,
ensuring the usual ordering (CFA, RA, FP). The padding data, a.k.a.
SFRAME_FRE_RA_OFFSET_INVALID is emitted in flexible FDEs when RA is
untracked but FP offsets follow. Trailing padding offsets should not
occur. Add a new function get_udata_size_in_bytes () to account for
sizing of unsigned register metadata.
gas/
* gen-sframe.c (get_udata_size_in_bytes): Get size of unsigned
int data in bytes.
(get_fre_num_offsets): Handle SFRAME_FDE_TYPE_FLEX.
(sframe_get_fre_offset_size): Account for register metadata
in flexible FDEs.
(output_sframe_row_entry_offsets): Add logic for flexible
FDE offset pairs.
(output_sframe_row_entry): Reset base register for flex FDEs.
(output_sframe_funcdesc): Emit FDE type in func_info2.
(sframe_xlate_ctx_init): Initialize flex_p.
(sframe_xlate_ctx_finalize): Finalize flex_p status.
(sframe_row_entry_initialize): Copy new deref tracking bits.
(sframe_xlate_do_offset): Set deref bits during translation.
* gen-sframe.h (struct sframe_row_entry): Add cfa_deref_p,
fp_deref_p, and ra_deref_p.
(struct sframe_func_entry): Add fde_flex_p.
(struct sframe_xlate_ctx): Add flex_p.
Up until now, for SFrame stack trace data generation (for default FDE
type), keeping two states sufficed to distinguish between the following
cases:
- the tracked entity is saved on a location on stack (identified by
SFRAME_FRE_ELEM_LOC_STACK)
- the tracked entity is in its designated register (identified by
SFRAME_FRE_ELEM_LOC_REG).
Soon though, we will start to generate a new FDE type
SFRAME_FDE_TYPE_FLEX, where in addition to above:
- the tracked entity may be saved in a temporary register
- the tracked entity may be saved at a "non-standard" location, e.g.,
not a simple CFA+offset based location
- and other cases
To effectively distinguish between the various states (necessary to
track for flex FDEs), define three states to track the location of each
tracked entity:
- SFRAME_FRE_ELEM_LOC_NONE: the entity is in its desginated location
(e.g., in case of AMD64 where the RA is at fixed offset from CFA)
- SFRAME_FRE_ELEM_LOC_REG: the entity is in a location based off a
register
- SFRAME_FRE_ELEM_LOC_STACK: the entity is in a location based off the
CFA
While at it, rather than asserting in sframe_xlate_do_offset (), reset
the fp_reg state to SFRAME_FRE_REG_INVALID. This is in preparation for
upcoming flex FDE generation patches.
Co-Authored-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
gas/
* gen-sframe.c (sframe_xlate_do_offset): Reset other state.
(sframe_xlate_do_same_value): Reset to SFRAME_FRE_ELEM_LOC_NONE.
* gen-sframe.h (SFRAME_FRE_ELEM_LOC_REG): New definition.
(SFRAME_FRE_ELEM_LOC_STACK): Likewise.
(SFRAME_FRE_ELEM_LOC_NONE): Likewise.
In SFrame V2, we did use the the term 'FDE Type' for the two designated
'PC Type' for the SFrame FDEs (SFRAME_FDE_TYPE_PCINC,
SFRAME_FDE_TYPE_PCMASK). In hindsight, 'FDE Type' was an inappropriate
term for the said intent. Fix this terminology by defining two new
constants:
- SFRAME_V3_FDE_PCTYPE_MASK
- SFRAME_V3_FDE_PCTYPE_INC
The old constants from V2 (SFRAME_FDE_TYPE_PCINC,
SFRAME_FDE_TYPE_PCMASK) remain, but are now unused in the codebase.
The term 'FDE Type' should be used for the actual FDE Types. In a
subsequent commit, we will add SFRAME_FDE_TYPE_FLEX FDE Type for SFrame
V3.
bfd/
* elf64-s390.c (_bfd_s390_elf_create_sframe_plt): Rename
inappropriate SFRAME_FDE_TYPE_PCINC to SFRAME_V3_FDE_PCTYPE_INC.
* elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Likewise. Also
rename inappropriate SFRAME_FDE_TYPE_PCMASK to
SFRAME_V3_FDE_PCTYPE_MASK.
gas/
* gen-sframe.c (output_sframe_funcdesc): Likewise.
* sframe-opt.c (sframe_convert_frag): Likewise.
libsframe/
* sframe-dump.c (dump_sframe_func_with_fres): Likewise.
* sframe.c (sframe_fre_check_range_p): Likewise.
(sframe_fde_create_func_info): Likewise.
libsframe/testsuite/
* libsframe.encode/encode-1.c: Likewise.
* libsframe.find/findfre-1.c: Likewise.
* libsframe.find/findfunc-1.c: Likewise.
* libsframe.find/plt-findfre-1.c: Likewise.
* libsframe.find/plt-findfre-2.c: Likewise.
The existing field func_info (in the SFrame FDE) is used to convey important
information around the encoding and interpretation of the rest of the
stack trace data for the respective SFrame FDE: the SFrame FRE type,
SFrame FDE PC type, etc.
Currently there is 1 bit left for AArch64, and 2 bits for AMD64, s390x
(and other future ABIs to be supported). Provision some additional
space now (specifically an additional 8-bits) for future needs for V3
and beyond.
Compared to V2, this now increases the size of SFrame FDE by 1 byte in
V3. In this patch, the additional func_info2 byte is not used
functionally yet. Hence, rather mechanical changes in libsframe, bfd
and libsframe/testsuite accompany. We will put func_info2 into use in a
later patch by reserving 5 of these bits for SFrame FDE types.
With the addition of a new byte for additional func info (func_info2),
add a new arg to allow usecases like textual dumper to get all data
members in one API: sframe_decoder_get_funcdesc_v3. To keep the APIs
symmetric looking, add new arg to sframe_encoder_add_funcdesc_v3 too.
Since bfd uses these APIs, carry out the mechanical change in the
respective APIs too. And of course, the testsuite which exercises these
APIs.
bfd/
* elf-sframe.c (_bfd_elf_merge_section_sframe): Get and set
func_info2.
* elf64-s390.c (_bfd_s390_elf_create_sframe_plt): Pass 0 for
func_info2 for SFrame FDE for PLT.
* elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Likewise.
gas/
* gen-sframe.c (output_sframe_funcdesc): Emit the uint8_t for
func_info2.
libsframe/
* sframe-dump.c (dump_sframe_func_with_fres):
* sframe.c (sframe_fde_tbl_init): Handle the new additional
member.
(sframe_encoder_write_fde): Likewise.
* sframe.c (sframe_decoder_get_funcdesc_v3): Update func_info2.
libsframe/testsuite/
* libsframe.decode/DATA2: Update data file with SFrame section
data.
* libsframe.encode/encode-1.c: Pass 0 for func_info2 arg.
* libsframe.find/findfre-1.c: Likewise.
* libsframe.find/findfunc-1.c: Likewise.
* libsframe.find/plt-findfre-1.c: Likewise.
* libsframe.find/plt-findfre-2.c: Likewise.
include/
* sframe.h: Add new uint8_t sfde_func_info2 to
sframe_func_desc_entry_v3.
* sframe-api.h (sframe_decoder_get_funcdesc_v3): New arg.
(sframe_encoder_add_funcdesc_v3): Likewise.
Update the SFrame generation logic in GAS to emit Function Descriptor Entries
(FDEs) for signal frames even when no Frame Row Entries (FREs) could be
generated.
Previously, create_sframe_all () would discard any FDE that failed
translation or resulted in zero FREs. However, for signal frames (marked
with .cfi_signal_frame), preserving the FDE may be valuable even without
stack offsets. The presence of the SFrame FDE with the 'Signal'
attribute may allow stack tracers to identify the frame as a signal
trampoline and potentially apply fallback handling, rather than treating
the PC range as having no stack trace info at all.
The patch modifies create_sframe_all () to detect translation errors for
signal frames, effectively allowing the generation of an empty FDE (0 FREs)
marked with the 'S' attribute.
gas/
* gen-sframe.c (sframe_fde_free): Add NULL check for safety.
(create_sframe_all): Allow FDEs for signal frames even if translation
encountered errors or produced no FREs.
gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: New test.
* gas/cfi-sframe/cfi-sframe-x86_64-signal-1.d: New test ensuring
signal frame FDE is emitted with 0 FREs.
* gas/cfi-sframe/cfi-sframe-x86_64-signal-1.s: New test.
Reserve a bit in function info byte in the SFrame FDE to designate
signal frames.
Also update the SFrame opt code in GAS and dumping routines in libsframe
to handle signal frame bit.
include/
* sframe.h (SFRAME_V3_FDE_SIGNAL_P): Extract signal frame bit.
(SFRAME_V3_FDE_UPDATE_SIGNAL_P): Set signal frame bit.
gas/
* gen-sframe.c (get_dw_fde_signal_p): New function to retrieve signal
frame state from DWARF FDE.
(sframe_v3_set_func_info): Renamed from sframe_v1_set_func_info.
Accept signal_p argument and encode it.
(sframe_set_version): Update ops to use sframe_v3_set_func_info.
(sframe_set_func_info): Pass signal_p to the ops hook.
(output_sframe_funcdesc): Retrieve signal frame marker and pass to
sframe_set_func_info.
* gen-sframe.h (struct sframe_version_ops): Update set_func_info
signature.
* sframe-opt.c (sframe_convert_frag): Preserve signal_p bit during
fragment conversion. While at it, use SFRAME_V3_* macros where
applicable.
libsframe/testsuite/
* gas/cfi-sframe/cfi-sframe-common-13.d: New test.
* gas/cfi-sframe/cfi-sframe-common-13.s: New test.
* gas/cfi-sframe/cfi-sframe.exp: Run new test.
libsframe/
* sframe-dump.c (dump_sframe_func_with_fres): Decode signal frame bit
and print "S" attribute in the dump output.
This change enables support text > 2 GiB in SFrame format.
Each SFrame FDE needs to hold information about the start PC of the
function it pertains to. Currently, the field 'sfde_func_start_address'
in SFrame FDE is encoded as a 32-bit offset to the start PC of the
function from the field itself.
In SFrame V2, this offset was a signed 32-bit offset. The signedness
gives the flexibility of having .sframe ELF section before or after the
.text* sections. But the size of 32-bit puts the limitation that
.sframe togther with the .text* sections must fit the 2 GiB range.
Currently, if the linker sees the offset not representable as 32-bit
signed offset, it issues an error (not seen in the wild, simulated by
forcing a function to align via an '.align 2147483648' directive):
test.o:(.sframe+0x1c): relocation truncated to fit: R_X86_64_PC32 against `.text'
make: *** [Makefile:7: all] Error 1
ATM, EH Frame also suffers with the same issue.
Moving forward, some cloud applications have been shown to be nearing
1.5 GiB threshold. Extending the offset to int64_t now seems to be good
choice to make now for future-proof'ing the sections.
The use of int64_t offset is done for all SFrame V3 sections. This
bump from int32_t to int64_t should not lead to an increase in the size
of SFrame sections, because of the following additional changes to the
SFrame FDE specification:
- Reduce the type of sfde_func_num_fres (from uint32_t to uint16_t)
- Remove the 2 bytes of padding (sfde_func_padding2). These served the
two-fold purpose of keeping FDE data aligned _and_ unused space for
future needs.
Now that the offset is int64_t, start using the
sframe_decoder_get_funcdesc_v3 () instead of
sframe_decoder_get_funcdesc_v2 () in GNU ld.
This patch changes the offset type in the SFrame FDE definition to an
int64_t. No further changes in gas are necessary because the code
already accounts for writing out as per the size of the member of the
struct:
emit_expr (&exp, sizeof_member (sframe_func_desc_entry,
sfde_func_start_offset));
bfd/
* elf-sframe.c (sframe_read_value): Signed offset for start PC
is 8-bytes now.
(_bfd_elf_merge_section_sframe): Likewise.
* elf64-s390.c (_bfd_s390_elf_create_sframe_plt): Use V3 API.
(elf_s390_finish_dynamic_sections): Signed offset for start PC
is 8-bytes now.
* elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Use V3 API.
(_bfd_x86_elf_finish_dynamic_sections): Signed offset for start
PC is 8-bytes now.
gas/
* sframe.c (output_sframe_funcdesc): Rename to
sfde_func_start_offset.
libsframe/
* libsframe/sframe.c (sframe_fde_tbl_init): Rename to
sfde_func_start_offset.
(flip_fde): Likewise.
(sframe_decoder_get_secrel_func_start_addr): Use int64_t.
(sframe_fre_check_range_p): Likewise.
(sframe_decoder_get_offsetof_fde_start_addr): Rename to
sfde_func_start_offset.
(sframe_get_funcdesc_with_addr_internal): Use int64_t.
(sframe_find_fre): Likewise.
(sframe_encoder_get_offsetof_fde_start_addr): Rename to
sfde_func_start_offset.
(sframe_encoder_add_funcdesc_internal): Use int64_t.
(sframe_encoder_add_funcdesc): Likewise. And rename to
sfde_func_start_offset.
(sframe_encoder_write_fde): Rename to sfde_func_start_offset.
libsframe/testsuite/
* libsframe.decode/DATA2: Regenerate the data file.
* libsframe.encode/encode-1.c: Use int64_t for start pc offset.
* libsframe.find/findfre-1.c: Likewise.
* libsframe.find/findfunc-1.c: Likewise.
* libsframe.find/plt-findfre-1.c: Likewise.
* libsframe.find/plt-findfre-2.c: Likewise.
include/
* sframe-api.h (sframe_find_fre): Update arg type to int64_t.
(sframe_encoder_add_funcdesc): Likewise.
* sframe.h: Change data type to int64_t.
Remove the unused sfde_func_padding2 member from the
sframe_func_desc_entry_v3 structure.
A later patch in this series reorganizes the members of the FDE
structure in a way explicit padding is no longer necessary to keep
natural alignment. So remove the explicit padding now.
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
include/
* sframe.h: Remove sfde_func_padding2 from
sframe_func_desc_entry_v3.
gas/
* gen-sframe.c (output_sframe_funcdesc): Stop writing
sfde_func_padding2.
libsframe/
* sframe.c (sframe_encoder_write_fde): Stop writing
sfde_func_padding2.
* testsuite/libsframe.decode/DATA2: Regenerate binary test data.
Reduce the size of the num_fres field in the Function Descriptor Entry
(FDE) from 32 bits to 16 bits.
The number of Frame Row Entries (FREs) for a single function is extremely
unlikely to exceed 65,535 in real-world scenarios. Reducing this field
saves 2 bytes per FDE, contributing to a smaller overall SFrame section size.
(BTW, these savings will be eaten up by a later commit which adds
support for text > 2 GiB by increasing an offset from int32_t to
int64_t).
Safety checks are added to the assembler to warn and skip SFrame FDE
generation if a function's FRE count exceeds UINT16_MAX.
Note regarding alignment: With the current patch, the members of
sframe_func_desc_entry_v3 are not at aligned boundaries anymore. Recall
that all sframe_func_desc_entry_v3 entries are stored together in the
"SFrame FDE sub-section" forming an index. Only after a later patch in
the series "[29/36] [SFrame-V3] include: gas: libsframe: split FDE into
desc and attr" will the alignment properties of SFrame index will be
restored.
include/
* sframe.h (sframe_func_desc_entry_v3): Change sfde_func_num_fres
type to uint16_t.
gas/
* gen-sframe.c (output_sframe_funcdesc): Write 2 bytes for num_fres
and assert it fits in uint16_t.
(sframe_do_fde): Add check to skip FDE emission if num_fres exceeds
UINT16_MAX.
libsframe/
* sframe.c (sframe_encoder_write_fde): Cast num_fres to uint16_t
to ensure correctly written out data.
* testsuite/libsframe.decode/DATA2: Update binary test data.
Bump version to SFRAME_VERSION_3. Introduce a new definition of SFrame
FDE for version 3, which is a duplicate of SFrame FDE in V2, for now.
In other words, no changes to the format specification yet.
GNU as emits SFrame V3 by default. SFrame encoder (ld) emits SFrame V3
sections. In a later commit, we will add a new command line option to
gas: --gsframe-3 which will bind the implementation in gas to emit
SFrame V3.
Also, adjust the testcases for the new version string
"SFRAME_VERSION_3".
bfd/
* elf-sframe.c (_bfd_elf_merge_section_sframe): Linker emits
the latest version by default.
* elf64-s390.c (_bfd_s390_elf_create_sframe_plt): Linker emitted
PLT sections are also SFRAME_VERSION_3.
* elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Likewise.
gas/
* gen-sframe.c (sframe_set_version): GAS emits SFrame V3 by
default.
(output_sframe): Likewise.
libsframe/
* sframe-dump.c (dump_sframe): Enable dumping for both
SFRAME_VERSION_2 and SFRAME_VERSION_3.
include/ChangeLog:
* sframe.h (SFRAME_VERSION_3): New definition.
(SFRAME_VERSION): Current version is now SFRAME_VERSION_3.
(SFRAME_V3_FDE_FUNC_INFO): New definition.
(SFRAME_V3_FDE_FRE_TYPE): Likewise.
(SFRAME_V3_FDE_PC_TYPE): Likewise.
(SFRAME_V3_AARCH64_FDE_PAUTH_KEY): Likewise.
(SFRAME_V3_FDE_UPDATE_PAUTH_KEY): Likewise.
binutils/testsuite/
* all affected tests: Replace SFRAME_VERSION_2 with
SFRAME_VERSION_3.
gas/testsuite/
* all affected tests: Likewise.
ld/testsuite/
* all affected tests: Likewise.
libsframe/testsuite/
* all affected tests: Likewise.
Add GAS and LD test cases for orphan REL HI16 relocation processing,
including verification of the addends produced as well as the warning
messages expected.
Due to the ordering used for the list of oustanding cached HI16 reloc
entries warnings for non-ELF links are issued in the reverse order
compared to one for ELF links. This is not considered a defect as all
the required warnings are produced in both cases, however separate
warning lists are required and included here for ELF and srec output.
Ever since commit 749b8d9d45 ("PATCH: ld/4208: `final link failed: Bad
value' when building Linux MIPS kernels."), which went in back in 2007,
<https://inbox.sourceware.org/binutils/20070320043504.GA7735@lucon.org/>,
we've been warning about unmatched HI16 REL relocations in the linker,
as it has been concluded in the discussion on PR ld/4208 that we have no
need to be forgiving about compiler bugs that lead to object files to be
made that are not compliant with the psABI.
However no corresponding update has ever been made to GAS, despite that
it's always helpful to issue a warning as early as possible in the build
process. In this particular case GAS also has more information to hand
as it always has the full original addend available that has been used
for both the high-part and the low-part relocation, while the linker has
to rely on the in-place value stored in the relocatable field by earlier
processing, which has necessarily been truncated. Therefore the linker
may miss cases where unrelated high-part and low-part relocations have
been put next to each other that had significantly different addends at
assembly time (small differences are deliberately permitted where they
are known not to affect any borrow from the high part).
Additionally GAS is able to point at the exact place in sources where
any offending orphan relocations have been used.
Update GAS to issue the warning then where applicable and remove an old
comment referring to GCC producing orphan HI16 relocations.
Test cases will be added with a separate change.
Update `bfd_finalize_section_relocs' to return status so that backends
can fail in this interface and propagate that to the respective callers.
Add suitable error reporting there. No failure cases in the existing
handlers though.
The `*_set_reloc' interface is to be called at the conclusion of section
relocation processing, however its name reflects a particular action to
take rather than the context of invocation. Implementation is already
backend-specific.
Rename the interface such as not to make its name artificially limit the
intended purpose. Update the callers and documentation accordingly. No
functional change.
Fold a separate call to `bfd_set_reloc' into SET_SECTION_RELOCS itself,
so that the GAS interface to this facility is contained in a single
invocation.
Currently both `write_relocs' and `obj_mach_o_reorder_section_relocs'
call `bfd_set_reloc', causing the function to be called twice by Mach-O
targets, such as `i386-darwin', once before target-specific processing
and again afterwards, which is at the very least fragile in terms of
assuming that any actions made by the function on the first invocation
won't interfere with the final intended result.
Set the macro by default to a plain call to `bfd_set_reloc', letting
backends override the macro, with the requirement now to factor in a
call to said function at the appropriate time. Backends can choose
whether to call `bfd_set_reloc' first (such as COFF), or last (such as
Mach-O), or at any other point in relation to their own additional
actions.
Update the COFF variant accordingly, moving it to a new function for a
better code structure, retaining functionality.
This is in preparation for `bfd_set_reloc' to return an error status.
Type offsetT is either defined as signed 32-bit or 64-bit integer
depending on whether BFD64 is defined. Do not test for whether an
offsetT value exceeds INT32_MIN..INT32_MAX for !BFD64 32-bit offsetT
(or INT64_MIN..INT64_MAX for BFD64 64-bit offsetT). This is always
true and may result in a compile error when using compiler option
-Werror=type-limits, such as the one resolved with commit
6b8fb74a94 ("gas: sframe: do not test whether offsetT exceeds
INT64_MIN..INT64_MAX") for BFD64 64-bit offsetT:
../../binutils-gdb/gas/gen-sframe.c: In function ‘get_offset_size_in_bytes’:
../../binutils-gdb/gas/gen-sframe.c:213:45: error: comparison is always true due to limited range of data type [-Werror=type-limits]
213 | else if ((sizeof (offsetT) > 4) && (value <= INT64_MAX && value >= INT64_MIN))
| ^~
../../binutils-gdb/gas/gen-sframe.c:213:67: error: comparison is always true due to limited range of data type [-Werror=type-limits]
213 | else if ((sizeof (offsetT) > 4) && (value <= INT64_MAX && value >= INT64_MIN))
| ^~
Instead of testing for whether the value is in range of
INT8_MIN..INT8_MAX, INT16_MIN..INT16_MAX, or INT32_MIN..INT32_MAX,
test whether the value is unchanged when casted to int8_t, int16_t,
or int32_t. This also improves readability.
gas/
* gen-sframe.c (get_offset_size_in_bytes): Simplify. Do not
test whether !BFD64 32-bit offsetT exceeds INT32_MIN..INT32_MAX.
Fixes: 58008ed4e6 ("gas: sframe: use standard min/max integer constants")
Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Call _bfd_elf_section_from_bfd_section to get the sh_link value from
the section flag 'o' directive, which may point to special sections,
like SHN_ABS or SHN_COMM. Update readelf to print the special section
names in the sh_link field and replace "internal->sh_link > num" with
"internal->sh_link >= num".
bfd/
PR gas/33744
* elf.c (assign_section_numbers): Call
_bfd_elf_section_from_bfd_section to get the sh_link value.
binutils/
PR gas/33744
* readelf.c (special_defined_section_index): New.
(get_32bit_section_headers): Don't warn special section indexes
in the sh_link field.
(get_64bit_section_headers): Likewise.
(process_section_headers): Print special defined section names.
gas/
PR gas/33744
* testsuite/gas/elf/elf.exp: Run PR gas/33744 tests.
* testsuite/gas/elf/sh-link-abs-1.d: New file.
* testsuite/gas/elf/sh-link-abs-2.d: Likewise.
* testsuite/gas/elf/sh-link-abs-3-32.d: Likewise.
* testsuite/gas/elf/sh-link-abs-3-64.d: Likewise.
* testsuite/gas/elf/sh-link-abs-4-32.d: Likewise.
* testsuite/gas/elf/sh-link-abs-4-64.d: Likewise.
* testsuite/gas/elf/sh-link-abs.s: Likewise.
* testsuite/gas/elf/sh-link-common-1.d: Likewise.
* testsuite/gas/elf/sh-link-common-2.d: Likewise.
* testsuite/gas/elf/sh-link-common-3-32.d: Likewise.
* testsuite/gas/elf/sh-link-common-3-64.d: Likewise.
* testsuite/gas/elf/sh-link-common-4-32.d: Likewise.
* testsuite/gas/elf/sh-link-common-4-64.d: Likewise.
* testsuite/gas/elf/sh-link-common.s: Likewise.
* testsuite/gas/elf/sh-link-large-common-1.d: Likewise.
* testsuite/gas/elf/sh-link-large-common-2.d: Likewise.
* testsuite/gas/elf/sh-link-large-common-3.d: Likewise.
* testsuite/gas/elf/sh-link-large-common-4.d: Likewise.
* testsuite/gas/elf/sh-link-large-common.s: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
A value of type offsetT, which is either a signed 32-bit or 64-bit
integer, cannot exceed the range of INT64_MIN..INT64_MAX. This
resolves the following compile error:
../../binutils-gdb/gas/gen-sframe.c: In function ‘get_offset_size_in_bytes’:
../../binutils-gdb/gas/gen-sframe.c:213:45: error: comparison is always true due to limited range of data type [-Werror=type-limits]
213 | else if ((sizeof (offsetT) > 4) && (value <= INT64_MAX && value >= INT64_MIN))
| ^~
../../binutils-gdb/gas/gen-sframe.c:213:67: error: comparison is always true due to limited range of data type [-Werror=type-limits]
213 | else if ((sizeof (offsetT) > 4) && (value <= INT64_MAX && value >= INT64_MIN))
| ^~
Fixes: 58008ed4e6 ("gas: sframe: use standard min/max integer constants")
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Replace the use of custom VALUE_{8|16|32|64}BIT constant definitions
with the standard INT{8|16|32|64}_{MIN|MAX} ones from stdint.h.
Besides improving readability this also fixes the issue that the
smallest representable signed 8/16/32-bit integer value was
erroneously sized as the next larger integer type. For example
get_offset_size_in_bytes (INT8_MIN) returned 2 instead of 1, due
to INT8_MIN (= -128) != -VALUE_8BIT (= -127):
(gdb) call get_offset_size_in_bytes (-127)
$1 = 1
(gdb) call get_offset_size_in_bytes (-128)
$2 = 2
gas/
* gen-sframe.c (VALUE_8BIT, VALUE_16BIT, VALUE_32BIT,
VALUE_64BIT): Remove.
(get_offset_size_in_bytes): Use standard min/max integer
constants.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
The versioned symbol with the @@@ syntax is a special case. If the symbol
is not defined, 2 `@'s will be removed from the versioned_name. Otherwise,
1 `@' will be removed. But for malformed versioned symbols may not have
@@@:
.symver foo,foo@@@version1
.symver foo,foo@version2
Check @@@ before renaming the versioned symbol.
PR gas/33745
* config/obj-elf.c (elf_frob_file_before_adjust): Check @@@ before
renaming the versioned symbol.
* testsuite/gas/symver/symver.exp: Run symver17.
* testsuite/gas/symver/symver17.l: New file.
* testsuite/gas/symver/symver17.s: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This fixes the following compile errors reported by Clang:
CC config/obj-elf-attr.o
../../gas/config/obj-elf-attr.c:64:21: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
64 | oav1_attr_info_init ()
| ^
| void
../../gas/config/obj-elf-attr.c:74:21: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
74 | oav1_attr_info_exit ()
| ^
| void
gas/
* config/obj-elf-attr.c (oav1_attr_info_init,
oav1_attr_info_exit): Explicitly code void parameter list.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
The aarch64 ABI states that long branch veneers may be added to
facilitate linking code that is beyond the range of a 26-bit call or
branch; but it requires that the target symbol be a function symbol.
Ensure that this latter condition is maintained by rejecting
relaxation of a static function symbol to it's section symbol.
Note that there should probably be a fix to the linker to enforce this
during link time. I've not done this for now because that might break
some existing object code that has been built with older versions of
gas. At some point we should revisit this.
This change also causes a small change in the LD testsuite: instead of
generating some veneers with the section name we now (correctly)
generate them using the name of the called function.
Update testsuite/gas/symver/symver15.l to expect:
Error: multiple versions [`foo@version2'|`foo@version1'] for symbol `foo'
* testsuite/gas/symver/symver15.l: Expect '|'.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Update or1k_apply_fix to handle all TLS relocations.
PR gas/33426
* config/tc-or1k.c (or1k_apply_fix): Handle all TLS relocations.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>