From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id D4197385801A; Tue, 21 Sep 2021 09:14:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4197385801A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Declare all constants with an associated size X-Act-Checkin: gcc X-Git-Author: Matthew Malcomson X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 97e6602b07e6c6e4349652d138837edd724f0b4a X-Git-Newrev: e3653f9e4f8bbd822de3ab7db22a3b10f8a9895d Message-Id: <20210921091440.D4197385801A@sourceware.org> Date: Tue, 21 Sep 2021 09:14:40 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Sep 2021 09:14:40 -0000 https://gcc.gnu.org/g:e3653f9e4f8bbd822de3ab7db22a3b10f8a9895d commit e3653f9e4f8bbd822de3ab7db22a3b10f8a9895d Author: Matthew Malcomson Date: Thu Sep 16 11:33:49 2021 +0100 Declare all constants with an associated size For PureCap we have introduced an indirection layer for loading the address of objects. For each indirected object, rather than calculate a pointer directly we load a capability from a table. The runtime populates this table. To populate the table we create a CAPINIT relocation for each entry. The linker requires a size for every symbol that we create a CAPINIT relocation for. This patch adds a `.size` directive to all constants with a DECL by implementing the `TARGET_ASM_DECLARE_CONSTANT_NAME` target hook. It adds a `.size` directive to every CONSTANT_POOL_ADDRESS_P symbol by adding the relevant code to `output_constant_pool_1`. It adds a `.size` directive to the .LTRAMP0 symbol in `assemble_trampoline_template`. There is still more work to do in this area -- there are more instances of this linker complaint in the testsuite -- but these are only for symbols that have an explicit size of zero. Such symbols are currently given the bounds of the entire section, and investigation into any alternative is a task for the future. This commit also adds a `.type` directive on each such object since we are adding the `.size` directive and specifying that these things are objects seems a nice add-on. We also introduce a helper function that emits the `.type` and `.size` directives for an object given its size. This patch removes a lot of link errors in the testsuite after the introduction of the indirection table containing `.capinit` relocations for any symbol that is loaded in code. Diff: --- gcc/config/aarch64/aarch64.c | 12 ++++++++++++ gcc/output.h | 5 +++++ gcc/varasm.c | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 6f34ee8c672..53b479e8c9d 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -11636,6 +11636,15 @@ aarch64_use_anchors_for_symbol_p (const_rtx x) return default_use_anchors_for_symbol_p (x); } +static void +aarch64_declare_constant_name (FILE *file, const char *name, + const_tree exp ATTRIBUTE_UNUSED, + HOST_WIDE_INT size) +{ + assemble_object_type_and_size (file, name, size); + return default_asm_declare_constant_name (file, name, exp, size); +} + /* Select appropriate section for constants depending on where we place literal pools. */ @@ -24814,6 +24823,9 @@ aarch64_libgcc_floating_mode_supported_p #undef TARGET_CAPABILITY_MODE #define TARGET_CAPABILITY_MODE aarch64_target_capability_mode +#undef TARGET_ASM_DECLARE_CONSTANT_NAME +#define TARGET_ASM_DECLARE_CONSTANT_NAME aarch64_declare_constant_name + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-aarch64.h" diff --git a/gcc/output.h b/gcc/output.h index 378fd196b2f..8705aeb2981 100644 --- a/gcc/output.h +++ b/gcc/output.h @@ -231,6 +231,11 @@ extern void assemble_external_libcall (rtx); /* Assemble a label named NAME. */ extern void assemble_label (FILE *, const char *); +/* Assemble the type and size directives associated with a label. + Assume that the label is an object (since all use cases at the moment are + for objects. */ +extern void assemble_object_type_and_size (FILE *, const char *, HOST_WIDE_INT); + /* Output to FILE (an assembly file) a reference to NAME. If NAME starts with a *, the rest of NAME is output verbatim. Otherwise NAME is transformed in a target-specific way (usually by the diff --git a/gcc/varasm.c b/gcc/varasm.c index d5f41d5ec25..c3c0d1959a5 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -2514,6 +2514,15 @@ assemble_label (FILE *file, const char *name) ASM_OUTPUT_LABEL (file, name); } +void +assemble_object_type_and_size (FILE *file, const char *in_name, + HOST_WIDE_INT size) +{ + const char *name = targetm.strip_name_encoding (in_name); + asm_fprintf (file, "\t.type\t%s, %%object\n", name); + asm_fprintf (file, "\t.size\t%s, %" PRId64 "\n", name, size); +} + /* Set the symbol_referenced flag for ID. */ void mark_referenced (tree id) @@ -2681,6 +2690,9 @@ assemble_trampoline_template (void) set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT); set_mem_size (initial_trampoline, TRAMPOLINE_SIZE); + /* Output the relevant size for the trampoline. */ + assemble_object_type_and_size (asm_out_file, label, TRAMPOLINE_SIZE); + return initial_trampoline; } @@ -4105,7 +4117,10 @@ output_constant_pool_1 (class constant_descriptor_rtx *desc, assemble_align (align); /* Output the label. */ - targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno); + char buf[42]; + ASM_GENERATE_INTERNAL_LABEL (buf, "LC", desc->labelno); + assemble_object_type_and_size (asm_out_file, buf, GET_MODE_SIZE (desc->mode)); + ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, buf); /* Output the data. Pass actual alignment value while emitting string constant to asm code