如今不推荐使用下划线开头的标签吗? [英] The leading underscore not recommended nowadays for labels?

查看:116
本文介绍了如今不推荐使用下划线开头的标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个新手,我想知道,现在不建议在下划线中不再使用主要的下划线吗?例如:

As a newbie, I wonder, is the leading underscore not recommended to use nowadays in assembly anymore? For example:

section .text
  global start ;; good
  ;; global _start ;; bad

  start:

也就是说,所有标签的名称中是否都不应包含前导下划线?它曾经在10到30年前使用过,但是现在没有,对吧?

That is, all the labels shouldn't not have the leading undercore in their names? It used to be used in 10-30 years ago, but nowadays not, right?

推荐答案

是否有可能与其他代码(当两者以静态或动态方式链接在一起)或工具(例如,前导下划线有链接器或调试器中的某些特殊含义/用途),那么您应该遵循工具和平台的常见要求.

If it's possible to run into compatibility/interoperability issues with other code (when both are linked together statically or dynamically) or with tools (e.g. when the leading underscores have some special meaning/purpose in the linker or debugger), then you should follow what's common for your tools and platform.

否则,这完全取决于您.例如,我编写了一个C编译器来生成汇编代码,然后将其汇编为ELF目标文件,然后将其与标准库链接在一起.对于DOS,Windows或Linux进行编译时,此过程相同.在所有情况下,公共/全局符号都有下划线,即使通常在ELF文件中不包含下划线也是如此.它们绝对不会给OS造成问题,因为OS看不到这些名称(可执行文件根本不包含符号表,无论如何它们都不需要执行).我有自己的链接器和我自己的标准库.我没有glibc之类的互操作性问题(我在标准库中使用系统调用). IOW,在我的编译器周围的狭小世界中,下划线根本不是问题.如果编译器受到欢迎(令人怀疑)并且人们开始以新的,有趣的和意想不到的方式使用它,则可能会成为问题.但是直到那时一切都可以正常工作.

Otherwise it's entirely up to you. For example, I've written a C compiler that generates assembly code, which is then assembled into ELF object files, which are then linked together with the standard library. This process is the same when compiling for DOS, Windows or Linux. In all cases public/global symbols have leading underscores even though it's common not to have those in ELF files. They in no way pose problems for the OS as the OS doesn't see those names (the executables simply don't contain symbol tables, which are not required for execution anyway). I have my own linker and my own standard library. I don't have interoperability issues with anything like glibc (I'm using system calls in my standard library). IOW, in the small world around my compiler the underscores aren't an issue at all. They may become an issue if the compiler gains popularity (doubtful) and people start using it in new, interesting and unintended ways. But until then things just work.

这篇关于如今不推荐使用下划线开头的标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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