C++: Difference between revisions

Jump to navigation Jump to search
1,661 bytes removed ,  9 years ago
[unchecked revision][unchecked revision]
No edit summary
Line 480:
 
See [[C++ Exception Support]].
 
== Solving .rodata Related Issues (GCC Only) ==
After a while, it may happen that your kernel starts crashing because of corrupt data on the .rodata section, typically missing or corrupt strings or even corrupt vtables, this usually happens because not all the sections GCC generates were properly linked in the final binary.
If your kernel happens to crash on a specific line of code that is not doing anything potentially harmful (ie: a function call), and after commenting some unrelated lines (probably lines that declare string constants), the kernel starts working as intended again, you should check your Linker Script for the following:
 
*sections should be page aligned
*text, data, rodata and bss input sections should be declared with a wildcard at the end *(.section_name*), since GCC may just use those names as a prefix for the actual section names, the wildcard character takes care of that.
*Put the (.rodata*) input sections insde the .text output section
*(.gnu.linkonce.t.*) and *(.gnu.linkonce.r.*) should also be included in .text
*(.ctor*) and (.dtor*) sections should be added to .text for constructors and destructors
*(.gnu.linkonce.d.*) should be included in .data
*(.gnu.linkonce.b.*) should be included in .bss
 
Here is a sample link.ld file:
<pre>
OUTPUT_FORMAT("elf64-x86-64")
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
*(.text*)
*(.gnu.linkonce.t.*)
*(.rodata*)
*(.gnu.linkonce.r.*)
*(SORT(.ctor*))
*(SORT(.dtor*))
. = ALIGN(4096);
}
data = .;
.data :
{
*(.data*)
*(.gnu.linkonce.d.*)
. = ALIGN(4096);
}
bss = .;
.bss :
{
*(.bss*)
*(.gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(4096);
}
}
</pre>
 
== Standard Template Library ==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu