Skip to content

Commit

Permalink
aarch64: Multiple adjustments to support the SMALL code model correct…
Browse files Browse the repository at this point in the history
…ly (#23)

LOCAL_LABEL_PREFIX has been changed to help the assembly compiler recognize local labels.
The anchors have been disabled as they use symbol + offset, which is not applicable for COFF AArch64.
Emitting locals has been replaced to use the .lcomm directive to declare uninitialized data without
defining an exact section.

aarch64.cc has been adjusted to prevent emitting symbol + offset for SYMBOL_SMALL_ABSOLUTE.
Instead, it will emit an offset with the "add" instruction to correct the address. The added code is a duplicate of the code from SYMBOL_SMALL_GOT_4G handling and will be refactored during the patch series preparation for the mailing list.

Functions and objects have been missing declarations. Binutils was not able to distinguish static from external,
an object from a function.

PE_COFF_LEGITIMIZE_EXTERN_DECL has been disabled, as it is needed for MEDIUM and LARGE models with -fPIC.
These models are not yet implemented for AArch64.

This fix relies on changes in binutils.
aarch64: Fix IMAGE_REL_ARM64_PAGEBASE_REL21 relocation and symbol reduction for relocations

This change resolves the following issues:
Relocation overflow when a struct is large
Relocation overflow issue when building FFmpeg with -O3
  • Loading branch information
eukarpov authored and github-actions committed Sep 24, 2024
1 parent eaa5331 commit 7d15ba5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
25 changes: 9 additions & 16 deletions gcc/config/aarch64/aarch64-coff.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
#ifndef GCC_AARCH64_COFF_H
#define GCC_AARCH64_COFF_H

#ifndef LOCAL_LABEL_PREFIX
# define LOCAL_LABEL_PREFIX ""
#endif
#undef LOCAL_LABEL_PREFIX
#define LOCAL_LABEL_PREFIX "."

/* Using long long breaks -ansi and -std=c90, so these will need to be
made conditional for an LLP64 ABI. */
Expand All @@ -37,6 +36,9 @@

#define TARGET_SEH 1

#undef TARGET_MAX_ANCHOR_OFFSET
#define TARGET_MAX_ANCHOR_OFFSET 0

#ifndef ASM_GENERATE_INTERNAL_LABEL
# define ASM_GENERATE_INTERNAL_LABEL(STRING, PREFIX, NUM) \
sprintf (STRING, "*%s%s%u", LOCAL_LABEL_PREFIX, PREFIX, (unsigned int)(NUM))
Expand All @@ -56,19 +58,10 @@
}
#endif

/* Output a local common block. /bin/as can't do this, so hack a
`.space' into the bss segment. Note that this is *bad* practice,
which is guaranteed NOT to work since it doesn't define STATIC
COMMON space but merely STATIC BSS space. */
#ifndef ASM_OUTPUT_ALIGNED_LOCAL
# define ASM_OUTPUT_ALIGNED_LOCAL(STREAM, NAME, SIZE, ALIGN) \
{ \
switch_to_section (bss_section); \
ASM_OUTPUT_ALIGN (STREAM, floor_log2 (ALIGN / BITS_PER_UNIT)); \
ASM_OUTPUT_LABEL (STREAM, NAME); \
fprintf (STREAM, "\t.space\t%d\n", (int)(SIZE)); \
}
#endif
#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \
( fputs (".lcomm ", (FILE)), \
assemble_name ((FILE), (NAME)), \
fprintf ((FILE), ",%u\n", (int)(ROUNDED)))

#define ASM_OUTPUT_SKIP(STREAM, NBYTES) \
fprintf (STREAM, "\t.space\t%d // skip\n", (int) (NBYTES))
Expand Down
12 changes: 11 additions & 1 deletion gcc/config/aarch64/aarch64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6095,6 +6095,15 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm)
case SYMBOL_TLSLE24:
case SYMBOL_TLSLE32:
case SYMBOL_TLSLE48:
if (const_offset != 0)
{
gcc_assert(can_create_pseudo_p ());
base = aarch64_force_temporary (int_mode, dest, base);
aarch64_add_offset (int_mode, dest, base, const_offset,
NULL_RTX, NULL_RTX, 0, false);
return;
}

aarch64_load_symref_appropriately (dest, imm, sty);
return;

Expand Down Expand Up @@ -31028,8 +31037,9 @@ aarch64_libgcc_floating_mode_supported_p
/* Limit the maximum anchor offset to 4k-1, since that's the limit for a
byte offset; we can do much more for larger data types, but have no way
to determine the size of the access. We assume accesses are aligned. */
#undef TARGET_MAX_ANCHOR_OFFSET
#ifndef TARGET_MAX_ANCHOR_OFFSET
#define TARGET_MAX_ANCHOR_OFFSET 4095
#endif

#undef TARGET_VECTORIZE_PREFERRED_DIV_AS_SHIFTS_OVER_MULT
#define TARGET_VECTORIZE_PREFERRED_DIV_AS_SHIFTS_OVER_MULT \
Expand Down
18 changes: 17 additions & 1 deletion gcc/config/aarch64/cygming.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,22 @@ extern void i386_pe_record_external_function (tree, const char *);

#define SUPPORTS_ONE_ONLY 1

#undef ASM_DECLARE_OBJECT_NAME
#define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \
do { \
fprintf (STREAM, "\t.def\t"); \
assemble_name (STREAM, NAME); \
fprintf (STREAM, ";\t.scl\t%d;\t.type\t%d;\t.endef\n", \
3, (int) 0 << 4); \
ASM_OUTPUT_LABEL ((STREAM), (NAME)); \
} while (0)

#undef ASM_DECLARE_FUNCTION_NAME
#define ASM_DECLARE_FUNCTION_NAME(STR, NAME, DECL) \
mingw_pe_declare_function_type (STR, NAME, TREE_PUBLIC (DECL)); \
aarch64_declare_function_name (STR, NAME, DECL)


/* Define this to be nonzero if static stack checking is supported. */
#define STACK_CHECK_STATIC_BUILTIN 1

Expand All @@ -298,7 +314,7 @@ extern void i386_pe_record_external_function (tree, const char *);
#undef GOT_ALIAS_SET
#define GOT_ALIAS_SET mingw_GOT_alias_set ()

#define PE_COFF_LEGITIMIZE_EXTERN_DECL 1
#define PE_COFF_LEGITIMIZE_EXTERN_DECL 0

#define HAVE_64BIT_POINTERS 1

Expand Down

0 comments on commit 7d15ba5

Please sign in to comment.