linux - 如何指定 scons 中使用的 linux 程序集的命令行 args 和 liker?

标签 linux assembly linker arguments scons

我在写汇编语言,程序是这样的:

.data
.equ b,3
.text
.globl _start
_start:
movl $2,%ebx
movl $b,%ecx
movl $1,%eax
int $0x80

我是在ubuntu 64bit版本下编译的。我希望得到一个 32 位版本,所以在 shell 下我可以这样做:

$ as my.s -32
$ ld a.out -o my

好的,没问题。我希望使用 scons 来管理这个过程,所以我有 SConstruct:

Program('my.s')

这将首先使用'as my.s -o my.o'和'gcc my.o -o my'进行编译,并报告'_start'重定义错误。

我的问题是:

How can I pass '-32' option to make sure I compile out 32bit version object file?

How can I specify the linker to be 'ld' but not 'gcc', to make sure I can use '_start' as entry point in my assembly source file?

最佳答案

为了将标志传递给汇编程序,ASFLAGS 应该可以工作。

为了将标志传递给链接器,LINKFLAGS 应该可以工作

要设置用于链接器的可执行文件,LINK(或 SHLINK)应该可以解决问题。

联机帮助页中列出了所有这些:http://scons.org/doc/production/HTML/scons-man.html

以下可能对您有用:

env=Environment(tools=['as','gnulink'])
env['ASFLAGS'] = '-32'
env['LINK'] = 'ld'
env.Program('my',['my.s'])

关于linux - 如何指定 scons 中使用的 linux 程序集的命令行 args 和 liker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39818000/

相关文章:

linux - 向分离 screen 发送命令,这会更改事件窗口

c++ - 调查 visual studio 程序集输出

c++ - 为什么在堆栈和堆上创建变量会产生相同的汇编代码?

c - 如何防止 Visual C 编译器优化掉 "unused"全局变量

linux - 如何删除文件中的换行符而不影响Linux中的实际行尾

linux - python 2.7 : How do I read single keypress in Linux (Including special characters)?

c++ - 使用 fread() 读取 BMP 的文件头

调试 assembly

c++ - 模块 ilink32.dll 中的访问冲突

linux - 由于对gcry- *符号的许多 undefined reference ,因此无法链接git2-rs