# LLD : \_\_start\_ and \_\_end\_ symbols for orphan sections

**URL:** <https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468>\
**Category:** LLVM Dev List Archives\
**Created:** [May 28, 2020, 8:20pm UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468 "2020-05-28T20:20:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moshtaghi\_Alireza](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Moshtaghi\_Alireza](https://discourse.llvm.org/u/Moshtaghi_Alireza)\
**Post date:** [May 28, 2020, 8:20pm UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/1 "2020-05-28T20:20:08Z")

</div>

lld does not seem to create the \_\_start and \_\_end symbols for orphan sections.

I would like to keep my linker script as generic as possible so how can I tell lld to create these symbols without having to add them in the linker script?

Thanks

A

---

<div class="post-metadata">

**Author:** ![MaskRay](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/maskray/32/81_2.png) [@MaskRay](https://discourse.llvm.org/u/MaskRay)\
**Post date:** [May 29, 2020, 6:30am UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/2 "2020-05-29T06:30:42Z")

</div>

It works for me.

SECTIONS {  
&nbsp;&nbsp;&nbsp;data : { \*(data) }  
}

.section data,"aw"  
.quad \_\_start\_orphan  
.quad \_\_stop\_orphan

.section orphan,"aw"  
.quad \_\_start\_data  
.quad \_\_stop\_data

Can you give an example \_\_start\_ or \_\_end\_ symbols are not defined for orphan sections?

---

<div class="post-metadata">

**Author:** ![Moshtaghi\_Alireza](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Moshtaghi\_Alireza](https://discourse.llvm.org/u/Moshtaghi_Alireza)\
**Post date:** [June 2, 2020, 7:00am UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/3 "2020-06-02T07:00:24Z")

</div>

You are right it creates them but sets the protected flag (STV\_PROTECTED) which seems to be the cause of my problem.  
How can I tell it to set the flag as STV\_DEFAULT?

Thanks  
A

&nbsp;&nbsp;&nbsp;&nbsp;NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.

&nbsp;&nbsp;&nbsp;&nbsp;\>lld does not seem to create the \_\_start and \_\_end symbols for orphan sections.  
&nbsp;&nbsp;&nbsp;&nbsp;\>I would like to keep my linker script as generic as possible so how can I tell lld to create these symbols without having to add them in the linker script?  
&nbsp;&nbsp;&nbsp;&nbsp;\>  
&nbsp;&nbsp;&nbsp;&nbsp;\>Thanks  
&nbsp;&nbsp;&nbsp;&nbsp;\>A

&nbsp;&nbsp;&nbsp;&nbsp;It works for me.

&nbsp;&nbsp;&nbsp;&nbsp;SECTIONS {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data : { \*(data) }  
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;.section data,"aw"  
&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_start\_orphan  
&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_stop\_orphan

&nbsp;&nbsp;&nbsp;&nbsp;.section orphan,"aw"  
&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_start\_data  
&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_stop\_data

&nbsp;&nbsp;&nbsp;&nbsp;Can you give an example \_\_start\_ or \_\_end\_ symbols are not defined for orphan sections?

---

<div class="post-metadata">

**Author:** ![Moshtaghi\_Alireza](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Moshtaghi\_Alireza](https://discourse.llvm.org/u/Moshtaghi_Alireza)\
**Post date:** [June 2, 2020, 2:46pm UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/4 "2020-06-02T14:46:13Z")

</div>

Sorry for the cryptic code but I had to modify stuff from original  
In the following example see the difference when you comment or uncomment the line in the linker script:  
============ test.c ============= :  
struct orphan\_dummy\_anno\_s {  
void (\*func)(void);  
};

static void dummy\_export\_dbg\_log\_init\_f (void) \_\_attribute\_\_ ((unused));  
static struct orphan\_dummy\_anno\_s const  
&nbsp;&nbsp;dummy\_export\_dbg\_log\_init\_linker\_set =  
&nbsp;&nbsp;{ dummy\_export\_dbg\_log\_init\_f, };  
\_\_asm\_\_ (".globl " "\_\_start\_set\_orphan\_dummy\_anno");  
\_\_asm\_\_ (".globl " "\_\_stop\_set\_orphan\_dummy\_anno");  
static void const  
&nbsp;&nbsp;\*\_\_set\_orphan\_dummy\_anno\_sym\_dummy\_export\_dbg\_log\_init\_linker\_set  
&nbsp;&nbsp;\_\_attribute\_\_ ((\_\_section\_\_ ("set\_" "orphan\_dummy\_anno")))  
&nbsp;&nbsp;\_\_attribute\_\_ ((\_\_used\_\_)) = &dummy\_export\_dbg\_log\_init\_linker\_set;  
============ linker\_script ============= :  
SECTIONS {  
&nbsp;&nbsp;&nbsp;data : { \*(data) }  
# when commented, the \_\_start and \_\_stop symbols will be protected. How can I keep it from setting it as protected?  
# set\_orphan\_dummy\_anno : { PROVIDE(\_\_start\_set\_orphan\_dummy\_anno = . ); \*(set\_orphan\_dummy\_anno) PROVIDE (\_\_stop\_set\_orphan\_dummy\_anno = . );}  
}  
============ howto ============= :  
LDFLAGS="-Bshareable -T ./linker\_script"  
clang -fPIC -c test.c  
ld.lld $LDFLAGS test.o -o test.so  
objdump -tT test.so

&nbsp;&nbsp;&nbsp;&nbsp;NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.

&nbsp;&nbsp;&nbsp;&nbsp;You are right it creates them but sets the protected flag (STV\_PROTECTED) which seems to be the cause of my problem.  
&nbsp;&nbsp;&nbsp;&nbsp;How can I tell it to set the flag as STV\_DEFAULT?

&nbsp;&nbsp;&nbsp;&nbsp;Thanks  
&nbsp;&nbsp;&nbsp;&nbsp;A

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>lld does not seem to create the \_\_start and \_\_end symbols for orphan sections.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>I would like to keep my linker script as generic as possible so how can I tell lld to create these symbols without having to add them in the linker script?  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>Thanks  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>A

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It works for me.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SECTIONS {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data : { \*(data) }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.section data,"aw"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_start\_orphan  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_stop\_orphan

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.section orphan,"aw"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_start\_data  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.quad \_\_stop\_data

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Can you give an example \_\_start\_ or \_\_end\_ symbols are not defined for orphan sections?

---

<div class="post-metadata">

**Author:** ![MaskRay](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/maskray/32/81_2.png) [@MaskRay](https://discourse.llvm.org/u/MaskRay)\
**Post date:** [June 2, 2020, 3:36pm UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/5 "2020-06-02T15:36:57Z")

</div>

> Sorry for the cryptic code but I had to modify stuff from original  
> In the following example see the difference when you comment or uncomment the line in the linker script:  
> ============ test.c ============= :  
> struct orphan\_dummy\_anno\_s {  
> void (\*func)(void);  
> };
> 
> static void dummy\_export\_dbg\_log\_init\_f (void) \_\_attribute\_\_ ((unused));  
> static struct orphan\_dummy\_anno\_s const  
> dummy\_export\_dbg\_log\_init\_linker\_set =  
> { dummy\_export\_dbg\_log\_init\_f, };  
> \_\_asm\_\_ (".globl " "\_\_start\_set\_orphan\_dummy\_anno");  
> \_\_asm\_\_ (".globl " "\_\_stop\_set\_orphan\_dummy\_anno");  
> static void const  
> \*\_\_set\_orphan\_dummy\_anno\_sym\_dummy\_export\_dbg\_log\_init\_linker\_set  
> \_\_attribute\_\_ ((\_\_section\_\_ ("set\_" "orphan\_dummy\_anno")))  
> \_\_attribute\_\_ ((\_\_used\_\_)) = &dummy\_export\_dbg\_log\_init\_linker\_set;  
> ============ linker\_script ============= :  
> SECTIONS {  
> &nbsp;&nbsp;data : { \*(data) }  
> # when commented, the \_\_start and \_\_stop symbols will be protected. How can I keep it from setting it as protected?  
> # set\_orphan\_dummy\_anno : { PROVIDE(\_\_start\_set\_orphan\_dummy\_anno = . ); \*(set\_orphan\_dummy\_anno) PROVIDE (\_\_stop\_set\_orphan\_dummy\_anno = . );}  
> }  
> ============ howto ============= :  
> LDFLAGS="-Bshareable -T ./linker\_script"  
> clang -fPIC -c test.c  
> ld.lld $LDFLAGS test.o -o test.so  
> objdump -tT test.so

Making \_\_start\_\* \_\_stop\_\* STV\_PROTECTED is a deliberate choice. See  
[https://reviews.llvm.org/D44566](https://reviews.llvm.org/D44566)  
Such symbols can still be exported to .dynsym (can be looked up from  
another shared object with dlopen) but prevent accidental symbol preemption..

---

<div class="post-metadata">

**Author:** ![Moshtaghi\_Alireza](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Moshtaghi\_Alireza](https://discourse.llvm.org/u/Moshtaghi_Alireza)\
**Post date:** [June 2, 2020, 5:05pm UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/6 "2020-06-02T17:05:22Z")

</div>

Okay  
Thank you

&nbsp;&nbsp;&nbsp;&nbsp;NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.

&nbsp;&nbsp;&nbsp;&nbsp;\>Sorry for the cryptic code but I had to modify stuff from original  
&nbsp;&nbsp;&nbsp;&nbsp;\>In the following example see the difference when you comment or uncomment the line in the linker script:  
&nbsp;&nbsp;&nbsp;&nbsp;\>============ test.c ============= :  
&nbsp;&nbsp;&nbsp;&nbsp;\>struct orphan\_dummy\_anno\_s {  
&nbsp;&nbsp;&nbsp;&nbsp;\> void (\*func)(void);  
&nbsp;&nbsp;&nbsp;&nbsp;\>};  
&nbsp;&nbsp;&nbsp;&nbsp;\>  
&nbsp;&nbsp;&nbsp;&nbsp;\>static void dummy\_export\_dbg\_log\_init\_f (void) \_\_attribute\_\_ ((unused));  
&nbsp;&nbsp;&nbsp;&nbsp;\>static struct orphan\_dummy\_anno\_s const  
&nbsp;&nbsp;&nbsp;&nbsp;\> dummy\_export\_dbg\_log\_init\_linker\_set =  
&nbsp;&nbsp;&nbsp;&nbsp;\> { dummy\_export\_dbg\_log\_init\_f, };  
&nbsp;&nbsp;&nbsp;&nbsp;\>\_\_asm\_\_ (".globl " "\_\_start\_set\_orphan\_dummy\_anno");  
&nbsp;&nbsp;&nbsp;&nbsp;\>\_\_asm\_\_ (".globl " "\_\_stop\_set\_orphan\_dummy\_anno");  
&nbsp;&nbsp;&nbsp;&nbsp;\>static void const  
&nbsp;&nbsp;&nbsp;&nbsp;\> \*\_\_set\_orphan\_dummy\_anno\_sym\_dummy\_export\_dbg\_log\_init\_linker\_set  
&nbsp;&nbsp;&nbsp;&nbsp;\> \_\_attribute\_\_ ((\_\_section\_\_ ("set\_" "orphan\_dummy\_anno")))  
&nbsp;&nbsp;&nbsp;&nbsp;\> \_\_attribute\_\_ ((\_\_used\_\_)) = &dummy\_export\_dbg\_log\_init\_linker\_set;  
&nbsp;&nbsp;&nbsp;&nbsp;\>============ linker\_script ============= :  
&nbsp;&nbsp;&nbsp;&nbsp;\>SECTIONS {  
&nbsp;&nbsp;&nbsp;&nbsp;\> data : { \*(data) }  
&nbsp;&nbsp;&nbsp;&nbsp;\># when commented, the \_\_start and \_\_stop symbols will be protected. How can I keep it from setting it as protected?  
&nbsp;&nbsp;&nbsp;&nbsp;\># set\_orphan\_dummy\_anno : { PROVIDE(\_\_start\_set\_orphan\_dummy\_anno = . ); \*(set\_orphan\_dummy\_anno) PROVIDE (\_\_stop\_set\_orphan\_dummy\_anno = . );}  
&nbsp;&nbsp;&nbsp;&nbsp;\>}  
&nbsp;&nbsp;&nbsp;&nbsp;\>============ howto ============= :  
&nbsp;&nbsp;&nbsp;&nbsp;\>LDFLAGS="-Bshareable -T ./linker\_script"  
&nbsp;&nbsp;&nbsp;&nbsp;\>clang -fPIC -c test.c  
&nbsp;&nbsp;&nbsp;&nbsp;\>ld.lld $LDFLAGS test.o -o test.so  
&nbsp;&nbsp;&nbsp;&nbsp;\>objdump -tT test.so

&nbsp;&nbsp;&nbsp;&nbsp;Making \_\_start\_\* \_\_stop\_\* STV\_PROTECTED is a deliberate choice. See  
&nbsp;&nbsp;&nbsp;&nbsp;[https://reviews.llvm.org/D44566](https://reviews.llvm.org/D44566)  
&nbsp;&nbsp;&nbsp;&nbsp;Such symbols can still be exported to .dynsym (can be looked up from  
&nbsp;&nbsp;&nbsp;&nbsp;another shared object with dlopen) but prevent accidental symbol preemption..

---

<div class="post-metadata">

**Author:** ![petrhosek](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/petrhosek/32/30_2.png) [@petrhosek](https://discourse.llvm.org/u/petrhosek)\
**Post date:** [June 2, 2020, 7:59pm UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/7 "2020-06-02T19:59:44Z")

</div>

In our case, we’d prefer the opposite that is for \_\_start/\_\_stop symbols to be always hidden (which is something Rafael also pointed out in [https://reviews.llvm.org/D44566#1041984](https://reviews.llvm.org/D44566#1041984)), currently this also requires a linker script on our side which is unfortunate. I have created a change [https://reviews.llvm.org/D55682](https://reviews.llvm.org/D55682) to provide the -z hidden-start-stop-symbol but this was rejected. I’m wondering if it’d make sense to extend that change to instead provide -z start-stop-symbol-visibility= which could be used to override visibility for \_\_start/\_\_stop symbol (i.e. default or hidden) which would match the frontend -fvisibility= flag. Would that be acceptable?

---

<div class="post-metadata">

**Author:** ![MaskRay](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/maskray/32/81_2.png) [@MaskRay](https://discourse.llvm.org/u/MaskRay)\
**Post date:** [June 2, 2020, 8:11pm UTC](https://discourse.llvm.org/t/lld-start-and-end-symbols-for-orphan-sections/55468/8 "2020-06-02T20:11:03Z")

</div>

> In our case, we'd prefer the opposite that is for \_\_start/\_\_stop symbols to  
> be always hidden (which is something Rafael also pointed out in  
> [⚙ D44566 [ELF] - Make \_\_start\_/\_\_stop\_\<section\_name\> symbols STV\_PROTECTED](https://reviews.llvm.org/D44566#1041984)), currently this also requires a  
> linker script on our side which is unfortunate. I have created a change  
> [⚙ D55682 [ELF] Add -z start-stop-visibility= to set \_\_start\_/\_\_stop\_ symbol visibility](https://reviews.llvm.org/D55682) to provide the -z hidden-start-stop-symbol  
> but this was rejected. I'm wondering if it'd make sense to extend that  
> change to instead provide -z start-stop-symbol-visibility= which could be  
> used to override visibility for \_\_start/\_\_stop symbol (i.e. default or  
> hidden) which would match the frontend -fvisibility= flag. Would that be  
> acceptable?

See pcc and ruiu's objection in the review [⚙ D55682 [ELF] Add -z start-stop-visibility= to set \_\_start\_/\_\_stop\_ symbol visibility](https://reviews.llvm.org/D55682)  
My feeling is similar: this extension looks of little value to me.

//extern char \_\_start\_f \_\_attribute\_\_((visibility("hidden")));  
extern char \_\_start\_f; // Fuchsia wants to write code like this, but its visibility is set to hidden due to -z hidden-start-stop-symbols

If you want to persist, asking binutils@sourceware.org may help.  
If they'd like to accept the extension, I think the option may get a  
change passing pcc and ruiu's bar for an extension.
