gpt4 book ai didi

c - GCC 将所有字符串存储在 .rodata 中

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:06 24 4
gpt4 key购买 nike

在我的 x86-64 内核中,我试图将 .rodata ELF 部分映射为只读。但是所有的字符串文字都存储在特定于文件的部分中,例如.rodata.str1.8。 GCC 是否有任何选项可以将所有字符串存储在 .rodata 中,或者我可以将 .rodata.str.x 连接到 .rodata使用 ldobjdump 或其他任何东西?

ENTRY(_start)

SECTIONS {
. = 0xC0100000;
kernel_memory_start = .;
.boot ALIGN(8) :
{
*(.multiboot)
}

.text ALIGN(4K) : AT(ADDR(.text) - 0xC0000000)
{
kernel_text_start = .;
*(.text)
}
kernel_text_end = .;
.rodata ALIGN(4K) : AT(ADDR(.rodata) - 0xC0000000)
{
kernel_rodata_start = .;
*(.rodata)
}
kernel_rodata_end = .;

.data ALIGN(4K) : AT(ADDR(.data) - 0xC0000000)
{
kernel_data_start = .;
*(.data)
}
kernel_data_end = .;

.bss ALIGN(4K) : AT(ADDR(.bss) - 0xC0000000)
{
kernel_bss_start = .;
*(.bss)
}
kernel_bss_end = .;
kernel_memory_end = .;
}

编译器标志:

gcc -ffreestanding -mcmodel=large -fno-pic -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-3dnow -mno-80387 -fno-unwind-tables ...

链接器标志:

ld -nostdlib -n ...

最佳答案

在您的链接器文件中,使用 *(.rodata*)

关于c - GCC 将所有字符串存储在 .rodata 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47952454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com