From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4C8313857C4F; Wed, 31 Mar 2021 02:20:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C8313857C4F From: "itirg1 at optusnet dot com.au" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99843] New: Making a function a friend of a class will hide function constructor priority if has constructor(n) attribute Date: Wed, 31 Mar 2021 02:20:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: itirg1 at optusnet dot com.au X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Mar 2021 02:20:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99843 Bug ID: 99843 Summary: Making a function a friend of a class will hide function constructor priority if has constructor(n) attribute Product: gcc Version: 9.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: itirg1 at optusnet dot com.au Target Milestone: --- When declaring a function a friend of a class and that function uses the __attribute__((constructor(priority))) attribute, the priority is lost. I h= ave only tested this on the arm-none-eabi-g++ on windows. In the code below I made a quick demo of the problem, all of the initialisa= tion functions correctly have a section called .init_array.(5 digit priority num= ber) containing a pointer to the function except for the function that was made a friend which is placed in .init_array which as a result the linker script w= ill place after the numbered ones. F:\Test>arm-none-eabi-g++ --version arm-none-eabi-g++ (GNU Arm Embedded Toolchain 9-2020-q3-update) 9.3.1 20200= 408 (release) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. F:\Test>cat testinit.cpp // Initialization order test void Init101(void) __attribute__((constructor(101))); void Init101(void) { while(1); } static void Init102(void) __attribute__((constructor(102))); static void Init102(void) { while(1); } namespace Something { void Init103(void) __attribute__((constructor(103))); void Init103(void) { while(1); } static void Init104(void) __attribute__((constructor(104))); static void Init104(void) { while(1); } class SomeClass { friend void Init105(void); private: int foo; public: int bar; }; SomeClass * AClassPtr =3D nullptr; void Init105(void) __attribute__((constructor(105))); void Init105(void) { if (AClassPtr =3D=3D nullptr) { AClassPtr =3D new SomeClass; } AClassPtr->foo =3D 219; } void Init106(void) __attribute__((constructor(106))); void Init106(void) { while(1); } } F:\Test>arm-none-eabi-g++ -mcpu=3Dcortex-m0 -c -fno-exceptions testinit.cpp F:\Test>arm-none-eabi-objdump -h -r -t testinit.o testinit.o: file format elf32-littlearm Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000004c 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1 .data 00000000 00000000 00000000 00000080 2**0 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000004 00000000 00000000 00000080 2**2 ALLOC 3 .init_array.00101 00000004 00000000 00000000 00000080 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 4 .init_array.00102 00000004 00000000 00000000 00000084 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 5 .init_array.00103 00000004 00000000 00000000 00000088 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 6 .init_array.00104 00000004 00000000 00000000 0000008c 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 7 .init_array 00000004 00000000 00000000 00000090 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 8 .init_array.00106 00000004 00000000 00000000 00000094 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 9 .comment 0000004d 00000000 00000000 00000098 2**0 CONTENTS, READONLY 10 .ARM.attributes 0000002c 00000000 00000000 000000e5 2**0 CONTENTS, READONLY SYMBOL TABLE: 00000000 l df *ABS* 00000000 testinit.cpp 00000000 l d .text 00000000 .text 00000000 l d .data 00000000 .data 00000000 l d .bss 00000000 .bss 00000000 l d .init_array.00101 00000000 .init_array.00101 00000006 l F .text 00000006 _ZL7Init102v 00000000 l d .init_array.00102 00000000 .init_array.00102 00000000 l d .init_array.00103 00000000 .init_array.00103 00000012 l F .text 00000006 _ZN9SomethingL7Init104Ev 00000000 l d .init_array.00104 00000000 .init_array.00104 00000000 l d .init_array 00000000 .init_array 00000000 l d .init_array.00106 00000000 .init_array.00106 00000000 l d .comment 00000000 .comment 00000000 l d .ARM.attributes 00000000 .ARM.attributes 00000000 g F .text 00000006 _Z7Init101v 0000000c g F .text 00000006 _ZN9Something7Init103Ev 00000000 g O .bss 00000004 _ZN9Something9AClassPtrE 00000018 g F .text 0000002c _ZN9Something7Init105Ev 00000000 *UND* 00000000 _Znwj 00000044 g F .text 00000006 _ZN9Something7Init106Ev RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 00000026 R_ARM_THM_CALL _Znwj 00000040 R_ARM_ABS32 _ZN9Something9AClassPtrE RELOCATION RECORDS FOR [.init_array.00101]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _Z7Init101v RELOCATION RECORDS FOR [.init_array.00102]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZL7Init102v RELOCATION RECORDS FOR [.init_array.00103]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9Something7Init103Ev RELOCATION RECORDS FOR [.init_array.00104]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9SomethingL7Init104Ev RELOCATION RECORDS FOR [.init_array]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9Something7Init105Ev RELOCATION RECORDS FOR [.init_array.00106]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9Something7Init106Ev F:\Test> Adding the __attribute__((constructor(105))) into the friend statement as w= ell fixes the problem and the correct output is then generated however in the f= irst case I think at the very least a warning should have been generated or idea= lly keeping the priority instead of quietly removing it. Changing the line with the friend statement to friend void Init105(void) __attribute__((constructor(105))); generated the correct sections F:\Test>arm-none-eabi-objdump -h -r -t testinit.o testinit.o: file format elf32-littlearm Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000004c 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 1 .data 00000000 00000000 00000000 00000080 2**0 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000004 00000000 00000000 00000080 2**2 ALLOC 3 .ARM.extab 00000000 00000000 00000000 00000080 2**0 CONTENTS, ALLOC, LOAD, READONLY, DATA 4 .ARM.exidx 00000030 00000000 00000000 00000080 2**2 CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA 5 .init_array.00101 00000004 00000000 00000000 000000b0 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 6 .init_array.00102 00000004 00000000 00000000 000000b4 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 7 .init_array.00103 00000004 00000000 00000000 000000b8 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 8 .init_array.00104 00000004 00000000 00000000 000000bc 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 9 .init_array.00105 00000004 00000000 00000000 000000c0 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 10 .init_array.00106 00000004 00000000 00000000 000000c4 2**2 CONTENTS, ALLOC, LOAD, RELOC, DATA 11 .comment 0000004d 00000000 00000000 000000c8 2**0 CONTENTS, READONLY 12 .ARM.attributes 0000002c 00000000 00000000 00000115 2**0 CONTENTS, READONLY SYMBOL TABLE: 00000000 l df *ABS* 00000000 testinit.cpp 00000000 l d .text 00000000 .text 00000000 l d .data 00000000 .data 00000000 l d .bss 00000000 .bss 00000000 l d .ARM.extab 00000000 .ARM.extab 00000000 l d .ARM.exidx 00000000 .ARM.exidx 00000000 l d .init_array.00101 00000000 .init_array.00101 00000006 l F .text 00000006 _ZL7Init102v 00000000 l d .init_array.00102 00000000 .init_array.00102 00000000 l d .init_array.00103 00000000 .init_array.00103 00000012 l F .text 00000006 _ZN9SomethingL7Init104Ev 00000000 l d .init_array.00104 00000000 .init_array.00104 00000000 l d .init_array.00105 00000000 .init_array.00105 00000000 l d .init_array.00106 00000000 .init_array.00106 00000000 l d .comment 00000000 .comment 00000000 l d .ARM.attributes 00000000 .ARM.attributes 00000000 g F .text 00000006 _Z7Init101v 0000000c g F .text 00000006 _ZN9Something7Init103Ev 00000018 g F .text 0000002c _ZN9Something7Init105Ev 00000000 *UND* 00000000 _Znwj 00000000 g O .bss 00000004 _ZN9Something9AClassPtrE 00000000 *UND* 00000000 __aeabi_unwind_cpp_pr0 00000044 g F .text 00000006 _ZN9Something7Init106Ev RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 00000026 R_ARM_THM_CALL _Znwj 00000040 R_ARM_ABS32 _ZN9Something9AClassPtrE RELOCATION RECORDS FOR [.ARM.exidx]: OFFSET TYPE VALUE 00000000 R_ARM_PREL31 .text 00000008 R_ARM_PREL31 .text 00000010 R_ARM_PREL31 .text 00000018 R_ARM_PREL31 .text 00000020 R_ARM_PREL31 .text 00000020 R_ARM_NONE __aeabi_unwind_cpp_pr0 00000028 R_ARM_PREL31 .text RELOCATION RECORDS FOR [.init_array.00101]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _Z7Init101v RELOCATION RECORDS FOR [.init_array.00102]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZL7Init102v RELOCATION RECORDS FOR [.init_array.00103]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9Something7Init103Ev RELOCATION RECORDS FOR [.init_array.00104]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9SomethingL7Init104Ev RELOCATION RECORDS FOR [.init_array.00105]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9Something7Init105Ev RELOCATION RECORDS FOR [.init_array.00106]: OFFSET TYPE VALUE 00000000 R_ARM_TARGET1 _ZN9Something7Init106Ev F:\Test>=