diff mbox series

[ARM/FDPIC,v5,05/21,ARM] FDPIC: Fix __do_global_dtors_aux and frame_dummy generation

Message ID 20190515124006.25840-6-christophe.lyon@st.com
State New
Headers show
Series FDPIC ABI for ARM | expand

Commit Message

Christophe Lyon May 15, 2019, 12:39 p.m. UTC
In FDPIC, we need to make sure __do_global_dtors_aux and frame_dummy
are referenced by their address, not by pointers to the function
descriptors.

2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>
	Mickaël Guêné <mickael.guene@st.com>

	* libgcc/crtstuff.c: Add support for FDPIC.

Change-Id: I0bc4b1232fbf3c69068fb23a1b9cafc895d141b1

-- 
2.6.3

Comments

Richard Sandiford July 12, 2019, 6:06 a.m. UTC | #1
Christophe Lyon <christophe.lyon@st.com> writes:
> In FDPIC, we need to make sure __do_global_dtors_aux and frame_dummy

> are referenced by their address, not by pointers to the function

> descriptors.

>

> 2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>

> 	Mickaël Guêné <mickael.guene@st.com>

>

> 	* libgcc/crtstuff.c: Add support for FDPIC.

>

> Change-Id: I0bc4b1232fbf3c69068fb23a1b9cafc895d141b1

>

> diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c

> index 4927a9f..159b461 100644

> --- a/libgcc/crtstuff.c

> +++ b/libgcc/crtstuff.c

> @@ -429,9 +429,18 @@ __do_global_dtors_aux (void)

>  #ifdef FINI_SECTION_ASM_OP

>  CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)

>  #elif defined (FINI_ARRAY_SECTION_ASM_OP)

> +#if defined(__FDPIC__)

> +__asm__(

> +    "   .section .fini_array\n"

> +    "   .align 2\n"

> +    "   .word __do_global_dtors_aux\n"

> +);

> +asm (TEXT_SECTION_ASM_OP);

> +#else /* defined(__FDPIC__) */

>  static func_ptr __do_global_dtors_aux_fini_array_entry[]

>    __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))

>    = { __do_global_dtors_aux };

> +#endif /* defined(__FDPIC__) */

>  #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */

>  static void __attribute__((used))

>  __do_global_dtors_aux_1 (void)


It'd be good to avoid hard-coding the pointer size.  Would it work to do:

__asm__("\t.equ\.t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");
extern char __do_global_dtors_aux_alias;
static void *__do_global_dtors_aux_fini_array_entry[]
   __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))
   = { &__do_global_dtors_aux_alias };

?  Similarly for the init_array.

AFAICT this and 02/21 are the only patches that aren't Arm-specific,
is that right?

Thanks,
Richard
Christophe Lyon July 12, 2019, 2:09 p.m. UTC | #2
On Fri, 12 Jul 2019 at 08:06, Richard Sandiford
<richard.sandiford@arm.com> wrote:
>

> Christophe Lyon <christophe.lyon@st.com> writes:

> > In FDPIC, we need to make sure __do_global_dtors_aux and frame_dummy

> > are referenced by their address, not by pointers to the function

> > descriptors.

> >

> > 2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>

> >       Mickaël Guêné <mickael.guene@st.com>

> >

> >       * libgcc/crtstuff.c: Add support for FDPIC.

> >

> > Change-Id: I0bc4b1232fbf3c69068fb23a1b9cafc895d141b1

> >

> > diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c

> > index 4927a9f..159b461 100644

> > --- a/libgcc/crtstuff.c

> > +++ b/libgcc/crtstuff.c

> > @@ -429,9 +429,18 @@ __do_global_dtors_aux (void)

> >  #ifdef FINI_SECTION_ASM_OP

> >  CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)

> >  #elif defined (FINI_ARRAY_SECTION_ASM_OP)

> > +#if defined(__FDPIC__)

> > +__asm__(

> > +    "   .section .fini_array\n"

> > +    "   .align 2\n"

> > +    "   .word __do_global_dtors_aux\n"

> > +);

> > +asm (TEXT_SECTION_ASM_OP);

> > +#else /* defined(__FDPIC__) */

> >  static func_ptr __do_global_dtors_aux_fini_array_entry[]

> >    __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))

> >    = { __do_global_dtors_aux };

> > +#endif /* defined(__FDPIC__) */

> >  #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */

> >  static void __attribute__((used))

> >  __do_global_dtors_aux_1 (void)

>

> It'd be good to avoid hard-coding the pointer size.  Would it work to do:

>

> __asm__("\t.equ\.t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");

> extern char __do_global_dtors_aux_alias;

> static void *__do_global_dtors_aux_fini_array_entry[]

>    __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))

>    = { &__do_global_dtors_aux_alias };

>

> ?  Similarly for the init_array.

>


I'll take a look, thanks.


> AFAICT this and 02/21 are the only patches that aren't Arm-specific,

> is that right?

Yes for compiler/libs changes.

There are also testsuite changes that potentially include other
targets in patches 16,17,18.

Thanks,

Christophe

> Thanks,

> Richard
Christophe Lyon Aug. 29, 2019, 3:35 p.m. UTC | #3
On 12/07/2019 08:06, Richard Sandiford wrote:
> Christophe Lyon <christophe.lyon@st.com> writes:

>> In FDPIC, we need to make sure __do_global_dtors_aux and frame_dummy

>> are referenced by their address, not by pointers to the function

>> descriptors.

>>

>> 2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>

>> 	Mickaël Guêné <mickael.guene@st.com>

>>

>> 	* libgcc/crtstuff.c: Add support for FDPIC.

>>

>> Change-Id: I0bc4b1232fbf3c69068fb23a1b9cafc895d141b1

>>

>> diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c

>> index 4927a9f..159b461 100644

>> --- a/libgcc/crtstuff.c

>> +++ b/libgcc/crtstuff.c

>> @@ -429,9 +429,18 @@ __do_global_dtors_aux (void)

>>   #ifdef FINI_SECTION_ASM_OP

>>   CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)

>>   #elif defined (FINI_ARRAY_SECTION_ASM_OP)

>> +#if defined(__FDPIC__)

>> +__asm__(

>> +    "   .section .fini_array\n"

>> +    "   .align 2\n"

>> +    "   .word __do_global_dtors_aux\n"

>> +);

>> +asm (TEXT_SECTION_ASM_OP);

>> +#else /* defined(__FDPIC__) */

>>   static func_ptr __do_global_dtors_aux_fini_array_entry[]

>>     __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))

>>     = { __do_global_dtors_aux };

>> +#endif /* defined(__FDPIC__) */

>>   #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */

>>   static void __attribute__((used))

>>   __do_global_dtors_aux_1 (void)

> 

> It'd be good to avoid hard-coding the pointer size.  Would it work to do:

> 

> __asm__("\t.equ\.t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");

> extern char __do_global_dtors_aux_alias;

> static void *__do_global_dtors_aux_fini_array_entry[]

>     __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))

>     = { &__do_global_dtors_aux_alias };

> 

> ?  Similarly for the init_array.

> 

OK, done.

> AFAICT this and 02/21 are the only patches that aren't Arm-specific,

> is that right?

> 

> Thanks,

> Richard

> .

>
From ea0eee1ddeddef92277ae68eac4af28994c2902c Mon Sep 17 00:00:00 2001
From: Christophe Lyon <christophe.lyon@linaro.org>

Date: Thu, 8 Feb 2018 11:12:52 +0100
Subject: [ARM/FDPIC v6 05/24] [ARM] FDPIC: Fix __do_global_dtors_aux and
 frame_dummy generation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In FDPIC, we need to make sure __do_global_dtors_aux and frame_dummy
are referenced by their address, not by pointers to the function
descriptors.

2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>
	Mickaël Guêné <mickael.guene@st.com>

	libgcc/
	* libgcc/crtstuff.c: Add support for FDPIC.

Change-Id: I0bc4b1232fbf3c69068fb23a1b9cafc895d141b1

diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
index 4927a9f..6659039 100644
--- a/libgcc/crtstuff.c
+++ b/libgcc/crtstuff.c
@@ -429,9 +429,17 @@ __do_global_dtors_aux (void)
 #ifdef FINI_SECTION_ASM_OP
 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
 #elif defined (FINI_ARRAY_SECTION_ASM_OP)
+#if defined(__FDPIC__)
+__asm__("\t.equ\t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");
+extern char __do_global_dtors_aux_alias;
+static void *__do_global_dtors_aux_fini_array_entry[]
+__attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))
+     = { &__do_global_dtors_aux_alias };
+#else /* defined(__FDPIC__) */
 static func_ptr __do_global_dtors_aux_fini_array_entry[]
   __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))
   = { __do_global_dtors_aux };
+#endif /* defined(__FDPIC__) */
 #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */
 static void __attribute__((used))
 __do_global_dtors_aux_1 (void)
@@ -473,9 +481,17 @@ frame_dummy (void)
 #ifdef __LIBGCC_INIT_SECTION_ASM_OP__
 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy)
 #else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
+#if defined(__FDPIC__)
+__asm__("\t.equ\t__frame_dummy_alias, frame_dummy\n");
+extern char __frame_dummy_alias;
+static void *__frame_dummy_init_array_entry[]
+__attribute__ ((__used__, section(".init_array"), aligned(sizeof(void *))))
+     = { &__frame_dummy_alias };
+#else /* defined(__FDPIC__) */
 static func_ptr __frame_dummy_init_array_entry[]
   __attribute__ ((__used__, section(".init_array"), aligned(sizeof(func_ptr))))
   = { frame_dummy };
+#endif /* defined(__FDPIC__) */
 #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
 
-- 
2.6.3
Richard Sandiford Aug. 30, 2019, 8:06 a.m. UTC | #4
Christophe Lyon <christophe.lyon@st.com> writes:
> On 12/07/2019 08:06, Richard Sandiford wrote:

>> Christophe Lyon <christophe.lyon@st.com> writes:

>>> In FDPIC, we need to make sure __do_global_dtors_aux and frame_dummy

>>> are referenced by their address, not by pointers to the function

>>> descriptors.

>>>

>>> 2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>

>>> 	Mickaël Guêné <mickael.guene@st.com>

>>>

>>> 	* libgcc/crtstuff.c: Add support for FDPIC.

>>>

>>> Change-Id: I0bc4b1232fbf3c69068fb23a1b9cafc895d141b1

>>>

>>> diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c

>>> index 4927a9f..159b461 100644

>>> --- a/libgcc/crtstuff.c

>>> +++ b/libgcc/crtstuff.c

>>> @@ -429,9 +429,18 @@ __do_global_dtors_aux (void)

>>>   #ifdef FINI_SECTION_ASM_OP

>>>   CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)

>>>   #elif defined (FINI_ARRAY_SECTION_ASM_OP)

>>> +#if defined(__FDPIC__)

>>> +__asm__(

>>> +    "   .section .fini_array\n"

>>> +    "   .align 2\n"

>>> +    "   .word __do_global_dtors_aux\n"

>>> +);

>>> +asm (TEXT_SECTION_ASM_OP);

>>> +#else /* defined(__FDPIC__) */

>>>   static func_ptr __do_global_dtors_aux_fini_array_entry[]

>>>     __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))

>>>     = { __do_global_dtors_aux };

>>> +#endif /* defined(__FDPIC__) */

>>>   #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */

>>>   static void __attribute__((used))

>>>   __do_global_dtors_aux_1 (void)

>> 

>> It'd be good to avoid hard-coding the pointer size.  Would it work to do:

>> 

>> __asm__("\t.equ\.t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");

>> extern char __do_global_dtors_aux_alias;

>> static void *__do_global_dtors_aux_fini_array_entry[]

>>     __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))

>>     = { &__do_global_dtors_aux_alias };

>> 

>> ?  Similarly for the init_array.

>> 

> OK, done.

>

>> AFAICT this and 02/21 are the only patches that aren't Arm-specific,

>> is that right?

>> 

>> Thanks,

>> Richard

>> .

>> 

>

> From ea0eee1ddeddef92277ae68eac4af28994c2902c Mon Sep 17 00:00:00 2001

> From: Christophe Lyon <christophe.lyon@linaro.org>

> Date: Thu, 8 Feb 2018 11:12:52 +0100

> Subject: [ARM/FDPIC v6 05/24] [ARM] FDPIC: Fix __do_global_dtors_aux and

>  frame_dummy generation

> MIME-Version: 1.0

> Content-Type: text/plain; charset=UTF-8

> Content-Transfer-Encoding: 8bit

>

> In FDPIC, we need to make sure __do_global_dtors_aux and frame_dummy

> are referenced by their address, not by pointers to the function

> descriptors.

>

> 2019-XX-XX  Christophe Lyon  <christophe.lyon@st.com>

> 	Micka«l Guªn© <mickael.guene@st.com>

>

> 	libgcc/

> 	* libgcc/crtstuff.c: Add support for FDPIC.


OK, thanks.

Richard

>

> Change-Id: I0bc4b1232fbf3c69068fb23a1b9cafc895d141b1

>

> diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c

> index 4927a9f..6659039 100644

> --- a/libgcc/crtstuff.c

> +++ b/libgcc/crtstuff.c

> @@ -429,9 +429,17 @@ __do_global_dtors_aux (void)

>  #ifdef FINI_SECTION_ASM_OP

>  CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)

>  #elif defined (FINI_ARRAY_SECTION_ASM_OP)

> +#if defined(__FDPIC__)

> +__asm__("\t.equ\t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");

> +extern char __do_global_dtors_aux_alias;

> +static void *__do_global_dtors_aux_fini_array_entry[]

> +__attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))

> +     = { &__do_global_dtors_aux_alias };

> +#else /* defined(__FDPIC__) */

>  static func_ptr __do_global_dtors_aux_fini_array_entry[]

>    __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))

>    = { __do_global_dtors_aux };

> +#endif /* defined(__FDPIC__) */

>  #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */

>  static void __attribute__((used))

>  __do_global_dtors_aux_1 (void)

> @@ -473,9 +481,17 @@ frame_dummy (void)

>  #ifdef __LIBGCC_INIT_SECTION_ASM_OP__

>  CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy)

>  #else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */

> +#if defined(__FDPIC__)

> +__asm__("\t.equ\t__frame_dummy_alias, frame_dummy\n");

> +extern char __frame_dummy_alias;

> +static void *__frame_dummy_init_array_entry[]

> +__attribute__ ((__used__, section(".init_array"), aligned(sizeof(void *))))

> +     = { &__frame_dummy_alias };

> +#else /* defined(__FDPIC__) */

>  static func_ptr __frame_dummy_init_array_entry[]

>    __attribute__ ((__used__, section(".init_array"), aligned(sizeof(func_ptr))))

>    = { frame_dummy };

> +#endif /* defined(__FDPIC__) */

>  #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */

>  #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
diff mbox series

Patch

diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
index 4927a9f..159b461 100644
--- a/libgcc/crtstuff.c
+++ b/libgcc/crtstuff.c
@@ -429,9 +429,18 @@  __do_global_dtors_aux (void)
 #ifdef FINI_SECTION_ASM_OP
 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
 #elif defined (FINI_ARRAY_SECTION_ASM_OP)
+#if defined(__FDPIC__)
+__asm__(
+    "   .section .fini_array\n"
+    "   .align 2\n"
+    "   .word __do_global_dtors_aux\n"
+);
+asm (TEXT_SECTION_ASM_OP);
+#else /* defined(__FDPIC__) */
 static func_ptr __do_global_dtors_aux_fini_array_entry[]
   __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))
   = { __do_global_dtors_aux };
+#endif /* defined(__FDPIC__) */
 #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */
 static void __attribute__((used))
 __do_global_dtors_aux_1 (void)
@@ -473,9 +482,18 @@  frame_dummy (void)
 #ifdef __LIBGCC_INIT_SECTION_ASM_OP__
 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy)
 #else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
+#if defined(__FDPIC__)
+__asm__(
+    "   .section .init_array\n"
+    "   .align 2\n"
+    "   .word frame_dummy\n"
+);
+asm (TEXT_SECTION_ASM_OP);
+#else /* defined(__FDPIC__) */
 static func_ptr __frame_dummy_init_array_entry[]
   __attribute__ ((__used__, section(".init_array"), aligned(sizeof(func_ptr))))
   = { frame_dummy };
+#endif /* defined(__FDPIC__) */
 #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */