-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UShell Shall NOT Look into symbol.txt for Symbols if Type=NOTYPE but Ndx != UND (UNDefined) #25
Comments
@hsiehken Can you push your code into some branch and tell me how to reproduce it? |
Related: #11 |
maybe this works? const double A = 1000000;
double getTimestamp()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec + ((double)tv.tv_usec) / A;
} |
This is a minimal example: __attribute__((section(".text")))
int main(int argc, char *argv[])
{
return (double)argc / 100000;
} symbol % readelf -s test
Symbol table '.symtab' contains 5 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS test.c
2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 .text
3: 0000000000000000 0 NOTYPE LOCAL DEFAULT 5 .LC0
4: 0000000000000000 21 FUNC GLOBAL DEFAULT 1 main relocation entries % readelf -r test
Relocation section '.rela.text' at offset 0x168 contains 1 entry:
Offset Info Type Sym. Value Sym. Name + Addend
00000000000c 000300000002 R_X86_64_PC32 0000000000000000 .LC0 - 4
Relocation section '.rela.eh_frame' at offset 0x180 contains 1 entry:
Offset Info Type Sym. Value Sym. Name + Addend
000000000020 000200000002 R_X86_64_PC32 0000000000000000 .text + 0 sections % readelf -S test
There are 14 section headers, starting at offset 0x218:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000000000000 00000040
0000000000000015 0000000000000000 AX 0 0 16
[ 2] .rela.text RELA 0000000000000000 00000168
0000000000000018 0000000000000018 I 11 1 8
[ 3] .data PROGBITS 0000000000000000 00000055
0000000000000000 0000000000000000 WA 0 0 1
[ 4] .bss NOBITS 0000000000000000 00000055
0000000000000000 0000000000000000 WA 0 0 1
[ 5] .rodata.cst8 PROGBITS 0000000000000000 00000058
0000000000000008 0000000000000008 AM 0 0 8
[...]
What we need to do is
Possible workaround
|
This puts the value in double A = 100000;
__attribute__((section(".text")))
int main(int argc, char *argv[])
{
return argc / A;
}
If a variable is const, we can put the data into .rodata by explicitly specifying it with attributes, but elf symbol still uses .LC0 for relocation. So we need to handle .LC0 symbol resolution in this case. __attribute__((section(".rodata")))
const double A = 100000;
__attribute__((section(".text")))
int main(int argc, char *argv[])
{
return argc / A;
}
|
Following UShell application code:
will be translated to
where .LC0 is a local variable segment containing some arithmetic magic numbers for dividing 1000000.
In the given case, gcc will put such .LC0 segment under 5th segment (.rodata related) and make a symbol table as followings:
the entry
3: 0000000000000000 0 NOTYPE LOCAL DEFAULT 5 .LC0
suggests, that .LC0 symbol is exactly existing in the same program at rodata segment, but loader.c:L637 will always try to reallocate it simply due to theNOTYPE
the symbol is being marked.The text was updated successfully, but these errors were encountered: