简体   繁体   English

在 x86-64 上具有自定义调用约定的 GCC 修改/自定义目标

[英]GCC modified/custom target with a custom calling convention on x86-64

I was wondering if it's possible (in a reasonable amount of time) to modify an existing or to define a new build target for gcc.我想知道是否有可能(在合理的时间内)修改现有的或为 gcc 定义新的构建目标。 The goal is to do minor modifications like changing the register in which the result of a function is returned or passing arguments using different registers than by the standard SystemV ABI for x86-64.目标是进行细微的修改,例如更改返回函数结果的寄存器或使用与 x86-64 的标准 SystemV ABI 不同的寄存器传递参数。

For example if I want to change the register for the return value of a function from RAX to R8 or returning a 64-byte struct using YMM0 and YMM1 without writing it myself using x86 asm code.例如,如果我想将函数返回值的寄存器从 RAX 更改为 R8,或者使用 YMM0 和 YMM1 返回一个 64 字节的结构而不使用 x86 asm 代码自己编写它。

(Background) I'm working on a small self-written OS so I was wondering if it's possible to not stick to System-V ABI or the one used by Microsoft for Windows. (背景)我正在开发一个小型的自行编写的操作系统,所以我想知道是否可以不坚持使用 System-V ABI 或 Microsoft 用于 Windows 的操作系统。 Compatibility with existing libs and stuff is not neccessary as every line of OS code is written by myself.与现有库和东西的兼容性不是必需的,因为每一行 OS 代码都是我自己编写的。 I'm only using gcc, ld and objdump.我只使用 gcc、ld 和 objdump。 No gdb, etc...没有gdb等...

If this is possible, where do I have to make such modifications in the gcc source or config files?如果可能,我必须在 gcc 源代码或配置文件中的何处进行此类修改? I've cloned the gcc git repo, but couldn't find a starting point for such a modification.我已经克隆了 gcc git repo,但找不到这种修改的起点。

This is all a bit theoretical, since I've never actually attempted a complete customisation.这有点理论化,因为我从未真正尝试过完全定制。 But I think it would be a reasonable project.但我认为这将是一个合理的项目。

GCC internals are documented in the GCC internals manual . GCC 内部结构记录在GCC 内部结构手册中 You probably don't need to read all of it in detail but you should at least try to get an overview of the basic structure.您可能不需要详细阅读所有内容,但您至少应该尝试大致了解基本结构。 It is all highly configurable.它都是高度可配置的。

The calling convention is configured in the "machine description" , which in part of the back end .调用约定是在“机器描述”中配置的,它是后端的一部分。 The most important part for the type of changes you are looking at is the description of the stack layout and calling conventions .您正在查看的更改类型的最重要部分是堆栈布局和调用约定的描述。 For example, you can change the way functions return scalar values using the TARGET_FUNCTION_VALUE hook , although you probably will also need to modify other parts of the machine description to correctly handle the register assignment.例如,您可以使用TARGET_FUNCTION_VALUE 钩子更改函数返回标量值的方式,尽管您可能还需要修改机器描述的其他部分以正确处理寄存器分配。

I'd suggest starting with a very small modification and thoroughly testing it (at least by verifying that the assembler output is as expected).我建议从一个非常小的修改开始并对其进行彻底的测试(至少通过验证汇编器输出是否符合预期)。 Then you can implement other modifications, as required.然后您可以根据需要实施其他修改。 As you develop the changes, keep a collection of test cases;在开发更改时,请保留一组测试用例; these will be extremely useful to help ensure that changes don't have unexpected interactions with each other.这些将非常有用,有助于确保更改之间不会发生意外的交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 x86_64 Linux 系统的 GCC 调用约定 - GCC calling convention for x86_64 Linux systems 为什么 x86-64 System V 调用约定在寄存器中传递 args 而不仅仅是堆栈? - Why does the x86-64 System V calling convention pass args in registers instead of just the stack? gcc参数寄存器溢出x86-64 - gcc argument register spilling on x86-64 GCC x86-64装配输出次优,为什么? - GCC x86-64 Suboptimal Assembly Output, why? 为x86-64体系结构安装gcc 3.0.1时出错 - Error installing gcc 3.0.1 for x86-64 architecture 对于 gcc 编译器,gcc 在不使用任何标志与 -O2 进行编译时针对哪个 x86-64 指令集? - For gcc compiler, what x86-64 instruction set does gcc target when you compile without any flags versus -O2? 在 64 位 (x86-64) 机器上构建 32 位 (x86) gcc-10.2.0 时出错 - Error building 32-bit (x86) gcc-10.2.0 on a 64-bit (x86-64) machine 为什么 x86-64 GCC 函数序言分配的堆栈比局部变量少? - Why does the x86-64 GCC function prologue allocate less stack than the local variables? 在gcc linux x86-64 C ++中有效的指针是什么? - What is a valid pointer in gcc linux x86-64 C++? 如何在linux上使用gcc汇编在x86-64中设置控制寄存器0(cr0)位 - how to set control register 0 (cr0) bits in x86-64 using gcc assembly on linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM