zoukankan      html  css  js  c++  java
  • 「操作系统」:Linker Use static Libraries

    While static libraries are useful and essential tools, they are also a source of confusion to programmers because of the way the Unix linker uses them to resolve external references.During the symbol resolution phase, the linker scans the relocatable object files and archives left to right in the same requential order that they appear on the complier driver's command line.(The driver automatically translates any .c files on the command line into .o files) During this scan, the linker maintains a set E of relocatable object files that will be merged to form the executable, a set U of unresolved symbols (i.e., symbols referred to , but not yet defined), and a set D of unresolved symbols (i.e., symbols referred to , but not ye defined), and a set D of symbols that have been defined in previous input files. Initially, E, U, and D are empty.

        For each input file f on the command line, the linker determines if f is an object file or an archive. If f is an object file, the linker add f to E, updates U and D to reflect the symbol definitions and referrences in f, and proceeds to the next input file.

        if f is an archive, the linker attempts to match the unresolved symbols in U against the symbols defined by the members of the archive. If some archive member, m, defines a symbol that resolves a reference in U, then m is added to E, and the linker updates U and D to reflect the symbol definitions and referencces in m. This process iterates over the member object files in the archive until a fixed point is reached where U and D no longer change. At this point, any member object files not contained in E are simply discarded and the linker proceeds to the next input file.

        if U is nonempty when the linker finishes scanning the input files on the command line, it prints an error and terminates . Otherwise, it merges and relocates the object files in E to build the output executable file.

        Unfortunately, this algorithm can result in some baffling link-time errors because the ordering of libraries and object files on the command line is significant. If the library that defines a symbol appears on the command line before the object file that references that symbol, then the reference will not be resolved and linking will fail.

  • 相关阅读:
    mybatis 控制台打印sql脚本
    删除git库中untracked files(未监控)的文件
    亚马逊云实例被攻击 一个月账单三百多美刀
    ubuntu下搜索文件
    django 富文本展示 以及 post提交出错
    亚马逊EC2弹性IP收费
    redis 相关命令
    使用XSHELL连接EC2虚拟机实例
    springMVC下集成active MQ发送邮件
    ubuntu下安装JDK并搭建activeMQ
  • 原文地址:https://www.cnblogs.com/sangoly/p/3618662.html
Copyright © 2011-2022 走看看