Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
handling undefined reference with lto
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5909

PostPosted: Wed Aug 21, 2019 5:27 am    Post subject: handling undefined reference with lto Reply with quote

Greetings,

I've stumbled on this topic: https://stackoverflow.com/questions/4156585/how-to-get-the-length-of-a-function-in-bytes, I took the second example and tried it with lto enabled, when I compile it I get undefined reference to vars, see:
Code:

$ cat test.c
#include <stdio.h>

int i;

 __attribute__((noinline, section(".mysection"))) void test_func (void)
{
    i++;
}

int main (void)
{
    extern unsigned char mysec_start[];
    extern unsigned char mysec_end[];

    printf ("Func len: %lu\n", mysec_end - mysec_start);
    test_func ();

    return 0;
}
$ gcc-7.3.0 -flto test.c -o test -DUSING_LTO
/tmp/ccSaKQu6.ltrans0.ltrans.o: In function `main':
<artificial>:(.text+0x5): undefined reference to `mysec_end'
<artificial>:(.text+0xa): undefined reference to `mysec_start'
collect2: error: ld returned 1 exit status


any idea how to make it compile?
_________________
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Back to top
View user's profile Send private message
DaggyStyle
Watchman
Watchman


Joined: 22 Mar 2006
Posts: 5909

PostPosted: Wed Aug 21, 2019 6:07 pm    Post subject: Reply with quote

after looking into the thread, this seems to work:
Code:

#include <stdio.h>

int i;

 __attribute__((noinline, section("mysection"))) void test_func (void)
{
    i++;
}

int main (void)
{
    extern unsigned char __start_mysection[];
    extern unsigned char __stop_mysection[];

    printf ("Func len: %lu\n", __stop_mysection - __start_mysection);
    test_func ();

    return 0;
}

_________________
Only two things are infinite, the universe and human stupidity and I'm not sure about the former - Albert Einstein
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum