8——man elf的翻译——Notes (Nhdr)

8 篇文章 0 订阅

Notes (Nhdr)

    ELF notes允许附加任意信息供系统使用。它们大部分情况是被内核文件使用(e_type of ET_CORE),
    但是很多projects定义它们自己的扩展。例如,GNU tool chain使用ELF notes将信息从链接器
    传递到C库。
        
    Note sections 包含一系列的notes(请看下面的定义)。Each note is followed by the name 
    field(n_namesz定义长度的那个)and then by the descriptor field(n_descsz定义长度的那个)
    and whose starting address has a 4 byte alignment.由于两个字段的长度都是任意的,所以在
    note结构中都没有定义它们。
    
    一个解析出两个连续的notes的例子应该能阐明它们在内存中的布局:
    
       void *memory, *name, *desc;
       Elf64_Nhdr *note, *next_note;

       /* The buffer is pointing to the start of the section/segment */
       note = memory;

       /* If the name is defined, it follows the note */
       name = note->n_namesz == 0 ? NULL : memory + sizeof(*note);

       /* If the descriptor is defined, it follows the name
          (with alignment) */

       desc = note->n_descsz == 0 ? NULL :
              memory + sizeof(*note) + ALIGN_UP(note->n_namesz, 4);

       /* The next note follows both (with alignment) */
       next_note = memory + sizeof(*note) +
                            ALIGN_UP(note->n_namesz, 4) +
                            ALIGN_UP(note->n_descsz, 4);
    
    请记住,n_type的解释取决于n_namesz字段定义的namespace。如果n_namesz没有设置,也就是为0,
    然后那就有两种notes的设置:一个为内核文件,另一个为其他ELF类型文件。如果namespace未知,
    then tools will usually fallback to these sets of notes as well.我看了一下有道翻译,感
    觉不太合适,还是原文比较好。有道是这么翻译的:然后工具通常也会回到这些笔记集。请参考
    
       typedef struct {
           Elf32_Word n_namesz;
           Elf32_Word n_descsz;
           Elf32_Word n_type;
       } Elf32_Nhdr;

       typedef struct {
           Elf64_Word n_namesz;
           Elf64_Word n_descsz;
           Elf64_Word n_type;
       } Elf64_Nhdr;
    
    n_namesz    name field的长度。在内存中内容会紧跟它之后。name为NUll的时候代表终止。
                例如,如果name是“GNU”,n_namesz就是4.
                
    n_descsz    描述符号字段的长度。在内存中内容会紧跟它之后。
    
    n_type        由name字段的值决定,有可能是下面这些中的一个:
    
                Core file (e_type = ET_CORE)
                    Notes被所有的内核文件使用。并且高度和操作系统相关或者和架构相关。
                    并且经常要求关闭和内核,C库,调试相关的联系。当namespace是默认值
                    (也就是n_namesz为0的时候)的时候是有用的。或者当namespace未知的
                    时候作为备份。
                    
                      NT_PRSTATUS          prstatus struct
                      NT_FPREGSET          fpregset struct
                      NT_PRPSINFO          prpsinfo struct
                      NT_PRXREG            prxregset struct
                      NT_TASKSTRUCT        task structure
                      NT_PLATFORM          String from sysinfo(SI_PLATFORM)
                      NT_AUXV              auxv array
                      NT_GWINDOWS          gwindows struct
                      NT_ASRS              asrset struct
                      NT_PSTATUS           pstatus struct
                      NT_PSINFO            psinfo struct
                      NT_PRCRED            prcred struct
                      NT_UTSNAME           utsname struct
                      NT_LWPSTATUS         lwpstatus struct
                      NT_LWPSINFO          lwpinfo struct
                      NT_PRFPXREG          fprxregset struct
                      NT_SIGINFO           siginfo_t (size might increase over time)
                      NT_FILE              Contains information about mapped files
                      NT_PRXFPREG          user_fxsr_struct
                      NT_PPC_VMX           PowerPC Altivec/VMX registers
                      NT_PPC_SPE           PowerPC SPE/EVR registers
                      NT_PPC_VSX           PowerPC VSX registers
                      NT_386_TLS           i386 TLS slots (struct user_desc)
                      NT_386_IOPERM        x86 io permission bitmap (1=deny)
                      NT_X86_XSTATE        x86 extended state using xsave
                      NT_S390_HIGH_GPRS    s390 upper register halves
                      NT_S390_TIMER        s390 timer register
                      NT_S390_TODCMP       s390 time-of-day (TOD) clock comparator register
                      NT_S390_TODPREG      s390 time-of-day (TOD) programmable register
                      NT_S390_CTRS         s390 control registers
                      NT_S390_PREFIX       s390 prefix register
                      NT_S390_LAST_BREAK   s390 breaking event address        
                      NT_S390_SYSTEM_CALL  s390 system call restart data
                      NT_S390_TDB          s390 transaction diagnostic block
                      NT_ARM_VFP           ARM VFP/NEON registers
                      NT_ARM_TLS           ARM TLS register
                      NT_ARM_HW_BREAK      ARM hardware breakpoint registers
                      NT_ARM_HW_WATCH      ARM hardware watchpoint registers
                      NT_ARM_SYSTEM_CALL   ARM system call number        
        
                n_name = GNU
                    GNU tool chain的扩展。
                    
                    NT_GNU_ABI_TAG
                        操作系统的ABI信息。desc field是4个words的大小:
                        
                        word 0:操作系统描述(ELF_NOTE_OS_LINUX, ELF_NOTE_OS_GNU,或者其他)
                        word 1:ABI的major版本
                        word 2:ABI的minor版本
                        word 3:ABI的subminor版本
                        
                    NT_GNU_HWCAP
                        Synthetic hwcap information.desc field是2个words的大小:
                        
                        word 0:条目的数量
                        word 1:按位控制条目的使能
                        
                        然后跟着变长的条目, one byte followed by a null-terminated hwcap name string.
                        这个字节可以按位测试是否使能,(1U << bit) & bit mask.
                        
                    NT_GNU_BUILD_ID
                        GNU ld生成的独特的build ID --build-id选项。desc由任意非零字节的内容组成。
                        
                    NT_GNU_GOLD_VERSION
                        The desc contains the GNU Gold linker version used.
                        
                Default/unknown namespace (e_type != ET_CORE)
                    当namespace是默认值
                    (也就是n_namesz为0的时候)的时候是有用的。或者当namespace未知的时候作为备份。
                    
                    NT_VERSION        某种类型的版本字符串
                    NT_ARCH            架构信息
                    
NOTES
        ELF第一次是在System V中出现的。ELF的格式是被采用的标准。
        
        扩展中的e_phnum,e_shnum和e_strndx是linux扩展的。Sun,BSD和AMD也支持它们;进一步的信息请参阅SEE ALSO.
        
SEE ALSO
        as(1),  elfedit(1),  gdb(1),  ld(1),  nm(1),  objdump(1),  readelf(1), size(1), strings(1), 
        strip(1), execve(2), dl_iterate_phdr(3), core(5)
        
        Hewlett-Packard, Elf-64 Object File Format.

        Santa Cruz Operation, System V Application Binary Interface.

        UNIX System Laboratories, "Object Files", Executable and Linking Format (ELF).

        Sun Microsystems, Linker and Libraries Guide.

        AMD64 ABI Draft, System V Application Binary Interface AMD64 Architecture Processor Supplement.
        
COLOPHON
        这是Linux的4.15release版本的man-pages版本。网址是:https://www.kernel.org/doc/man-pages/
        
                                        2017-09-15
 

到目前为止翻译结束,里面由很多不尽如人意的地方,有一些还是直接粘贴的翻译。我对ELF的研究也不是很深入,暂时也只能做到这个样子了。希望读者理解。水平一般,能力有限。翻译工作比我想象的要困难很多。

                                                                                                                                           2019年4月5日 清明 公司

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值