how to export a function in GAS assembler?

柔情痞子 提交于 2019-12-10 11:30:02

问题


Hi I have the following assembly code ,

.export __ls__11NSDOM_EncapFf
.text 
__ls__11NSDOM_EncapFf:
/* first load the symbolic constant*/
movq _IEEE_FP@GOTPCREL(%rip), %r8  /*%r8 is a scratch register*/
movq (%r8), %r9  /* %r9 and %r11 are scratch registers*/
movl (%r9), %r11d
/* second, see if it is zero and branch accordingly */
test %r11d, %r11d   /* zero call TNS procedure */
                    /* non-zero call IEEE procedure */
je  ____ls__11NSDOM_EncapFf_tns/* constant equals 0 */
jmp  ____ls__11NSDOM_EncapFf_ieee/* constant not equal to 0 */
ret

I compile the .s file to .o file(compilation is fine) , but when I link this .o with other .o files it is failing due to unresolved reference to _ls_11NSDOM_EncapFf. I am using GNU assembler 2.19.1 on HP Non stop system, X86-64 bit architecture. Please help me to resolve the issue.


回答1:


You'll need to set your symbol global for it to be externally linkable;

.text 
.global __ls__11NSDOM_EncapFf          /* Sets the symbol externally linkable */
__ls__11NSDOM_EncapFf:
/* first load the symbolic constant*/
...



回答2:


Use .global symbol or .globl symbol (see Using as - Assembler directives).



来源:https://stackoverflow.com/questions/17696633/how-to-export-a-function-in-gas-assembler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!