什么是GCC编译器选项以在x86中获取Segment Override前缀 [英] what is GCC compiler option to get Segment Override prefix in x86

查看:185
本文介绍了什么是GCC编译器选项以在x86中获取Segment Override前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的内存布局(在增加内存地址中):

I have memory layout (In Increasing memory addr) like :

代码段(0-4k),数据段(4k-8k),堆栈段(8k-12k),CustomData段(12k-16k).

Code Section (0-4k), Data Section(4k-8k), Stack Section(8k-12k), CustomData Section(12k-16k).

我在自定义数据"部分中放置了一些特殊的数组,结构.

I have put some special arrays, structs in Custom Data Section.

据我所知,数据段(#DS)Selector将用于任何与数据相关的编译器代码.

As i know, Data Segment (#DS)Selector will be used for any Data related compiler code.

因此,默认情况下,数据节(4k-8k)的所有操作都将具有#DS.除了某些可以在其中使用ES的strop之外.喜欢:

So Data Section(4k-8k) will have #DS by default for all operation. Except some str op where ES may be used. Like:

mov    $0xc00,%eax
addl   $0xd, (%eax)

但是,我想使用Extra Segment(#ES)选择器进行CustomData访问.我将为ES使用不同的基本和限制定义一个新的GDT条目.像:

But, I want to use Extra Segment(#ES) selector for CustomData access. I would define a new GDT entry for ES with different Base and Limit. like:

mov    $0x3400,%eax
addl   $0xd, %es:(%eax)

所以我的问题是:

GCC是否有任何x86编译器标志,可用于告诉编译器使用#ES进行CustomData节代码访问.?

Does GCC has any x86 compiler flag, which can be used to tell compiler that use #ES for CustomData Section code access.?

意味着,编译器标志将使用#ES为CustomData部分生成代码.?

Means, compiler flag which will generate code using #ES for CustomData Section.?

预先感谢!

推荐答案

引用 clang语言扩展文档

#define GS_RELATIVE __attribute__((address_space(256)))
int foo(int GS_RELATIVE *P) {
  return *P;
}

编译至(在X86-32上):

Which compiles to (on X86-32):

_foo:
        movl    4(%esp), %eax         # load the arg
        movl    %gs:(%eax), %eax      # use it with its prefix
        ret

地址空间256是gs,257是fs,258是ss.

address-space 256 is gs, 257 is fs, and 258 is ss.

文档没有提及es;编译器通常假定es = ds,因此如果他们基于调整选项选择这样做,则可以为inmcpy/memset自由地内联rep movsrep stos. memcpymemset的库实现也可能在某些CPU上使用重复存储/移动.相关:为什么std :: fill(0)比std :: fill(1)慢?

The docs don't mention es; compilers normally assume that es=ds so they can freely inline rep movs or rep stos for memcpy / memset if they choose to do so based on tuning options. Library implementations of memcpy or memset may also use rep stos/movs on some CPUs. Related: Why is std::fill(0) slower than std::fill(1)?

很明显,这确实是底层的东西,只有在您已经设置了GS或FS基址的情况下,它才有意义. (wrfsbase).请注意,i386 Linux使用gs进行用户空间中的线程本地存储,而x86-64 Linux使用fs.

Obviously this is really low-level stuff, and only makes sense if you've already set the GS or FS base address. (wrfsbase). Beware that i386 Linux uses gs for thread-local storage in user-space, while x86-64 Linux uses fs.

我不知道gcc,ICC或MSVC这样的扩展名.

I'm not aware of extensions like this for gcc, ICC, or MSVC.

好吧,GNU C中有__thread,它将根据目标平台使用%gs:%fs:前缀. gcc`__thread`如何工作?.

Well, there is __thread in GNU C, which will use %gs: or %fs: prefixes as appropriate for the target platform. How does the gcc `__thread` work?.

这篇关于什么是GCC编译器选项以在x86中获取Segment Override前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆