我正在创建一个带有C-ABI接口的C++库.
这就是GCC如何处理关于重整的外部"C"限定符:
namespace x {
extern "C" int monkey(int x) {
return 1;
}
int chimpanzee(int x) {
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
相关nm产出:
00000000004005cd T _ZN1x10chimpanzeeEi
00000000004005bf T monkey
Run Code Online (Sandbox Code Playgroud)
问题: 我想在命名空间中保留C-ABI中涉及的函数,以便最大程度地重用.重要说明:编译库后,我将为链接器提供映射文件(GCC)或模块定义文件(MSVC).
在我看来,C库几乎从来没有问题混合使用不同版本编译的库或(有时)甚至不同的编译器,并且许多语言似乎能够直接或以最小的努力与C库交互.
这是因为ABI是标准的吗?
我使用以下语句在我的android应用程序中包含了opencv:
compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'
Run Code Online (Sandbox Code Playgroud)
现在仅使用了四分之二,这既浪费空间,又可能浪费速度。有没有办法只加载/编译属于体系结构的库?我已经阅读了针对不同处理器体系结构的Gradle android build,但是该库使用libs文件夹,因此具有自己的include。我有所有通过gradle导入的库。
我正在尝试调试用户报告的特定问题的 Android 应用程序。我已经创建了一个虚拟设备,但是当涉及到 ABI 版本时,我不知道如何找出手机正在使用的版本(如果手机甚至使用这个版本!)。
(我真的不知道这意味着什么/用于什么,这没有帮助)
有没有办法找到设备是否正在使用(armabi-v7a、x86、x86_64、x86(googleAPIs)。
任何帮助表示赞赏。
我正在尝试通过编译简单的函数和查看输出来学习汇编.
我正在考虑调用其他库中的函数.这是一个玩具C函数,它调用其他地方定义的函数:
void give_me_a_ptr(void*);
void foo() {
give_me_a_ptr("foo");
}
Run Code Online (Sandbox Code Playgroud)
这是gcc生成的程序集:
$ gcc -Wall -Wextra -g -O0 -c call_func.c
$ objdump -d call_func.o
call_func.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <foo>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: bf 00 00 00 00 mov $0x0,%edi
9: e8 00 00 00 00 callq e <foo+0xe>
e: 90 nop
f: 5d pop %rbp
10: c3 retq
Run Code Online (Sandbox Code Playgroud)
我期待着类似的东西call <give_me_a_ptr@plt>.为什么在它知道give_me_a_ptr定义的位置之前它会跳到相对位置?
我也很困惑mov $0, %edi.这看起来像是在传递一个空指针 …
请考虑以下计划:
#include <stdio.h>
void my_f(int);
int main()
{
int i = 15;
my_f(i);
}
void my_f(int i)
{
int j[2] = {99, 100};
printf("%d\n", j[-2]);
}
Run Code Online (Sandbox Code Playgroud)
我的理解是,活动记录(又名堆栈帧)为my_f()应该是这样的:
------------
| i | 15
------------
| Saved PC | Address of next instruction in caller function
------------
| j[0] | 99
------------
| j[1] | 100
------------
Run Code Online (Sandbox Code Playgroud)
我期望j [-2]打印15,但它打印0.有人请解释我在这里缺少什么?我在OS X 10.5.8上使用GCC 4.0.1(是的,我生活在一块岩石下,但除了这里的重点之外).
为什么al包含汇编中的矢量参数数量?
为什么向量参数与被调用者的正常参数有任何不同?
raxSystemV ABI:和中仅定义了 2 个返回寄存器rdx,但structs 的大小可以远大于 16 字节,并且可以具有 2 个以上的成员。所以我考虑了下面的例子:
struct test{
unsigned long a;
char *b;
unsigned long c;
};
struct test get_struct(void){
return (struct test){.a = 10, .b = "abc", .c = 20};
}
void get_struct2(struct test *tst){
struct test tmp = {.a = 10, .b = "abc", .c = 20};
*tst = tmp;
}
Run Code Online (Sandbox Code Playgroud)
这些函数的O3编译代码看起来几乎相同:gcc
Dump of assembler code for function get_struct:
0x0000000000000820 <+0>: lea rdx,[rip+0x2f6] # 0xb1d
0x0000000000000827 <+7>: …Run Code Online (Sandbox Code Playgroud) 尝试使用以下命令从空项目创建轮子setup.py:
from setuptools import setup
setup(name='bla', version='1')
Run Code Online (Sandbox Code Playgroud)
我调用python setup.py bdist_wheel --python-tag py35 --plat-name linux_x86_64并得到
bla-1-py35-none-linux_x86_64.whl
python -V: Python 3.6.9
uname -p: x86_64
Run Code Online (Sandbox Code Playgroud)
我正在用 C 创建纤维线程系统,遵循https://graphitemaster.github.io/ Fibers/ 。我有一个设置和恢复上下文的函数,我想要完成的是将函数作为具有自己的堆栈的 Fiber 启动。Linux、x86_64 SysV ABI。
\nextern void restore_context(struct fiber_context*);\nextern void create_context(struct fiber_context*);\n\nvoid foo_fiber()\n{\n printf("Called as a fiber");\n exit(0);\n}\n\nint main()\n{\n const uint32_t stack_size = 4096 * 16;\n const uint32_t red_zone_abi = 128;\n\n char* stack = aligned_alloc(16, stack_size);\n char* sp = stack + stack_size - red_zone_abi;\n\n struct fiber_context c = {0};\n c.rip = (void*)foo_fiber;\n c.rsp = (void*)sp;\n\n restore_context(&c);\n}\nRun Code Online (Sandbox Code Playgroud)\n其中restore_context代码如下:
\n.type restore_context, @function\n.global restore_context\nrestore_context:\n movq 8*0(%rdi), %r8\n\n # Load new stack pointer.\n movq 8*1(%rdi), %rsp\n\n …Run Code Online (Sandbox Code Playgroud)