[llvm-dev] LLD : __start_ and __end_ symbols for orphan sections

Moshtaghi, Alireza via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 2 07:46:13 PDT 2020


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 {
   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


On 6/2/20, 12:00 AM, "llvm-dev on behalf of Moshtaghi, Alireza via llvm-dev" <llvm-dev-bounces at lists.llvm.org on behalf of llvm-dev at lists.llvm.org> wrote:

    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.




    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

    On 5/28/20, 11:30 PM, "Fangrui Song" <maskray at google.com> wrote:

        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.




        On 2020-05-28, Moshtaghi, Alireza via llvm-dev wrote:
        >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

        It works for me.

        SECTIONS {
           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?

    _______________________________________________
    LLVM Developers mailing list
    llvm-dev at lists.llvm.org
    https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list