GNU ld链接器 lang_process()(二)

一、ldemul_create_output_section_statements()

位于lang_process()中11行  。  该函数用于创建与目标有关的输出段的语句。这些语句将用于描述输出段的属性和分配。

void
ldemul_create_output_section_statements (void)
{if (ld_emulation->create_output_section_statements)ld_emulation->create_output_section_statements ();
}
static ld_emulation_xfer_type *ld_emulation;
  /* Create any output sections needed by the target.  */void	(*create_output_section_statements) (void);  // 14
typedef struct ld_emulation_xfer_struct {/* Run before parsing the command line and script file.Set the architecture, maybe other things.  */void   (*before_parse) (void); // 1/* Handle the SYSLIB (low level library) script command.  */void   (*syslib) (char *);  // 2/* Handle the HLL (high level library) script command.  */void   (*hll) (char *);  // 3/* Run after parsing the command line and script file.  */void   (*after_parse) (void);  // 4/* Run after opening all input files, and loading the symbols.  */void   (*after_open) (void);  // 5/* Run after allocating output sections.  */void   (*after_allocation)  (void);  // 6/* Set the output architecture and machine if possible.  */void   (*set_output_arch) (void);  // 7/* Decide which target name to use.  */char * (*choose_target) (int, char**);  // 8/* Run before allocating output sections.  */void   (*before_allocation) (void);  // 9/* Return the appropriate linker script.  */char * (*get_script) (int *isfile);  // 10/* The name of this emulation.  */char *emulation_name;  // 11/* The output format.  */char *target_name;  // 12/* Run after assigning values from the script.  */void	(*finish) (void);  // 13/* Create any output sections needed by the target.  */void	(*create_output_section_statements) (void);  // 14/* Try to open a dynamic library.  ARCH is an architecture name, andis normally the empty string.  ENTRY is the lang_input_statementthat should be opened.  */bfd_boolean (*open_dynamic_archive)(const char *arch, struct search_dirs *,struct lang_input_statement_struct *entry);  // 15/* Place an orphan section.  Return TRUE if it was placed, FALSE ifthe default action should be taken.  This field may be NULL, inwhich case the default action will always be taken.  */lang_output_section_statement_type *(*place_orphan)(asection *, const char *, int);  // 16/* Run after assigning parsing with the args, but beforereading the script.  Used to initialize symbols used in the script.  */void	(*set_symbols) (void);  // 17/* Parse args which the base linker doesn't understand.Return TRUE if the arg needs no further processing.  */bfd_boolean (*parse_args) (int, char **);  // 18/* Hook to add options to parameters passed by the base linker togetopt_long and getopt_long_only calls.  */void (*add_options)(int, char **, int, struct option **, int, struct option **);  // 19/* Companion to the above to handle an option.  Returns TRUE if it isone of our options.  */bfd_boolean (*handle_option) (int);  // 20/* Run to handle files which are not recognized as object files orarchives.  Return TRUE if the file was handled.  */bfd_boolean (*unrecognized_file)(struct lang_input_statement_struct *);  // 21/* Run to list the command line options which parse_args handles.  */void (* list_options) (FILE *);  // 22/* Run to specially handle files which *are* recognized as objectfiles or archives.  Return TRUE if the file was handled.  */bfd_boolean (*recognized_file)(struct lang_input_statement_struct *);  // 23/* Called when looking for libraries in a directory specifiedvia a linker command line option or linker script option.Files that match the pattern "lib*.a" have already been scanned.(For VMS files matching ":lib*.a" have also been scanned).  */int (* find_potential_libraries)(char *, struct lang_input_statement_struct *);  // 24/* Called when adding a new version pattern.  PowerPC64-ELF usesthis hook to add a pattern matching ".foo" for every "foo".  */struct bfd_elf_version_expr * (*new_vers_pattern)(struct bfd_elf_version_expr *);  // 25/* Called when printing the map file, in case there areemulation-specific sections for it.  */void (*extra_map_file_text)(bfd *, struct bfd_link_info *, FILE *);  // 26} ld_emulation_xfer_type;

二、lang_place_undefineds ()

 将命令行中所有未定义的符号加入哈希表中

结构体类型:

struct bfd_sym_chain

  • 这是一个结构体定义,表示符号链的链接列表节点。每个节点包含指向下一个节点的指针和指向字符字符串的指针(可能是符号名称)。
  • typedef struct bfd_sym_chain ldlang_undef_chain_list_type

  • 这行代码为struct bfd_sym_chain创建了类型别名ldlang_undef_chain_list_type,以便更容易使用和声明这种类型的变量。
  • #define ldlang_undef_chain_list_head entry_symbol.next

  • 这似乎是一个预处理器宏,将ldlang_undef_chain_list_head定义为entry_symbol.next。它可能用作访问符号链节点的next字段的简写。
struct bfd_sym_chain
{struct bfd_sym_chain *next;const char *name;
};typedef struct bfd_sym_chain ldlang_undef_chain_list_type;#define ldlang_undef_chain_list_head entry_symbol.next
函数: 

static void lang_place_undefineds(void)

  • 这是一个函数定义的开始,名为lang_place_undefineds。它是一个静态函数,意味着它仅限于当前的翻译单元。这个函数的目的是遍历未定义符号(ldlang_undef_chain_list_type)的列表,并为每个符号的名称调用insert_undefined
static void
lang_place_undefineds (void)
//   /* Add to the hash table all undefineds on the command line.  */
{ldlang_undef_chain_list_type *ptr;for (ptr = ldlang_undef_chain_list_head; ptr != NULL; ptr = ptr->next)insert_undefined (ptr->name);
}

static void insert_undefined(const char *name)

  • 这是另一个静态函数定义,名为insert_undefined。它以字符串(name)作为参数。这个函数的目的是将未定义符号插入符号表中。它首先使用bfd_link_hash_lookup在哈希表中查找符号,如果找不到,则使用bfd_link_add_undef添加它。

 

/* Insert NAME as undefined in the symbol table.  */static void
insert_undefined (const char *name)
{struct bfd_link_hash_entry *h;h = bfd_link_hash_lookup (link_info.hash, name, TRUE, FALSE, TRUE);if (h == NULL)einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));if (h->type == bfd_link_hash_new){h->type = bfd_link_hash_undefined;h->u.undef.abfd = NULL;bfd_link_add_undef (link_info.hash, h);}
}

bfd_link_hash_lookupbfd_hash_lookup函数:

  • 这些函数用于在哈希表中查找条目。bfd_link_hash_lookup似乎用于在符号哈希表中查找条目,而bfd_hash_lookup是一个更一般的哈希表查找函数。这些函数通过对输入字符串进行哈希并在哈希表中搜索相应的条目来工作。
  • bfd_hash_insert函数:

  • 此函数用于将新条目插入哈希表。它为条目分配内存,计算哈希值,并将条目插入哈希表的适当位置。如果需要,它还处理表的大小调整。
struct bfd_link_hash_entry *
bfd_link_hash_lookup (struct bfd_link_hash_table *table,const char *string,bfd_boolean create,  // Tbfd_boolean copy,  // Fbfd_boolean follow)  // T
{struct bfd_link_hash_entry *ret;ret = ((struct bfd_link_hash_entry *)bfd_hash_lookup (&table->table, string, create, copy));if (follow && ret != NULL){while (ret->type == bfd_link_hash_indirect|| ret->type == bfd_link_hash_warning)ret = ret->u.i.link;}return ret;
}
struct bfd_hash_entry *
bfd_hash_lookup (struct bfd_hash_table *table,const char *string,bfd_boolean create,  // Tbfd_boolean copy)  // F
{unsigned long hash;struct bfd_hash_entry *hashp;unsigned int len;unsigned int _index;hash = bfd_hash_hash (string, &len);_index = hash % table->size;for (hashp = table->table[_index];hashp != NULL;hashp = hashp->next){if (hashp->hash == hash&& strcmp (hashp->string, string) == 0)return hashp;}if (! create)return NULL;if (copy){char *new_string;new_string = (char *) objalloc_alloc ((struct objalloc *) table->memory,len + 1);if (!new_string){bfd_set_error (bfd_error_no_memory);return NULL;}memcpy (new_string, string, len + 1);string = new_string;}return bfd_hash_insert (table, string, hash);
}
struct bfd_hash_entry *
bfd_hash_insert (struct bfd_hash_table *table,const char *string,unsigned long hash)
{struct bfd_hash_entry *hashp;unsigned int _index;hashp = (*table->newfunc) (NULL, table, string);if (hashp == NULL)return NULL;hashp->string = string;hashp->hash = hash;_index = hash % table->size;hashp->next = table->table[_index];table->table[_index] = hashp;table->count++;if (!table->frozen && table->count > table->size * 3 / 4){unsigned long newsize = higher_prime_number (table->size);struct bfd_hash_entry **newtable;unsigned int hi;unsigned long alloc = newsize * sizeof (struct bfd_hash_entry *);/* If we can't find a higher prime, or we can't possibly allocthat much memory, don't try to grow the table.  */if (newsize == 0 || alloc / sizeof (struct bfd_hash_entry *) != newsize){table->frozen = 1;return hashp;}newtable = ((struct bfd_hash_entry **)objalloc_alloc ((struct objalloc *) table->memory, alloc));if (newtable == NULL){table->frozen = 1;return hashp;}memset (newtable, 0, alloc);for (hi = 0; hi < table->size; hi ++)while (table->table[hi]){struct bfd_hash_entry *chain = table->table[hi];struct bfd_hash_entry *chain_end = chain;while (chain_end->next && chain_end->next->hash == chain->hash)chain_end = chain_end->next;table->table[hi] = chain_end->next;_index = chain->hash % newsize;chain_end->next = newtable[_index];newtable[_index] = chain;}table->table = newtable;table->size = newsize;}return hashp;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/135714.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Netty心跳检测

文章目录 一、网络连接假死现象二、服务器端的空闲检测三、客户端的心跳报文 客户端的心跳检测对于任何长连接的应用来说&#xff0c;都是一个非常基础的功能。要理解心跳的重要性&#xff0c;首先需要从网络连接假死的现象说起。 一、网络连接假死现象 什么是连接假死呢&…

外贸网站优化常用流程和一些常识

外贸网站google排名&#xff0c;总以为是单个网页标签的优化过程。 显然&#xff0c;这些观点都是错误的,九凌网络是做谷歌优化服务&#xff0c;九凌网络跟大家分享外贸网站Google优化常用流程和一些常识需要做以下几个步骤&#xff1a; 第一步&#xff1a;网站诊断&#xff0…

OpenHarmony 4.0 Release 编译异常处理

一、环境配置 编译环境&#xff1a;Ubuntu 20.04 OpenHarmony 软件版本&#xff1a;4.0 Release 设备平台&#xff1a;rk3568 二、下拉代码 参考官网步骤&#xff1a; OpenHarmony 4.0 Release 源码获取 repo init -u https://gitee.com/openharmony/manifest -b OpenHarmo…

接口测试 Mock 实战(二) | 结合 jq 完成批量化的手工 Mock

因为本章的内容是使用jq工具配合完成&#xff0c;因此在开始部分会先花一定的篇幅介绍jq机器使用&#xff0c;如果读者已经熟悉jq&#xff0c;可以直接跳过这部分。 先来看应用场景&#xff0c;App 经常会有一些信息展示的列表页&#xff0c;比如商家的菜品、股票的公司、文章的…

uni-app:js实现数组中的相关处理-数组复制

一、slice方法-浅拷贝 使用分析 创建一个原数组的浅拷贝&#xff0c;对新数组的修改不会影响到原数组slice() 方法创建了一个原数组的浅拷贝&#xff0c;这意味着新数组和原数组中的对象引用是相同的。因此&#xff0c;当你修改新数组中的对象时&#xff0c;原数组中相应位置的…

【网络】UDP协议

UDP协议 一、传输层1、再谈端口号2、两个命令 二、UDP协议1、UDP协议格式2、UDP的解包和分用3、UDP的特点4、UDP使用注意事项5、基于UDP的应用层协议 一、传输层 我们以前在学习HTTP等应用层协议时&#xff0c;为了便于理解&#xff0c;简单的认为HTTP协议是将请求和响应直接发…

如何使用 NFTScan NFT API 在 Arbitrum 网络上开发 Web3 应用

Arbitrum 是以太坊的 Layer 2 扩容方案&#xff0c;为以太坊面临的高 gas 费和网络拥堵问题&#xff0c;提供了一个解决方案。作为 Layer 1 的以太坊基础层受每秒只能验算 15 笔交易的限制&#xff0c;在目前以太坊使用需求庞大的情况下&#xff0c;局限了以太坊的可扩展性。Ar…

安全防御——四、防火墙理论知识

安全防御 一、防火墙1、防火墙是如何诞生的2、防火墙如何分类2.1 软件型防火墙2.1.1 个人防火墙2.1.2 网关型防火墙 3、硬件型防火墙4、防火墙的技术类型5、代理服务器什么是代理 6、防火墙的接口模式7、防火墙抵御的攻击7.1 DDoS攻击7.2 单包攻击7.3 用户行为不受控7.4 威胁安…

使用 Threejs 从基础开始构建 3D 地球

需求 threejs学习-3D 地球 实现&#xff1a; 1、使用粒子效果模拟宇宙星空 2、贴图、模型等资源的加载 3、加载资源的监听 4、效果合成器 EffectComposer 的初级使用 5、在地球上设置坐标以及坐标涟漪动画 6、标点间建立飞线 7、简单动画建议先浏览一遍git地址上代码&#xff…

xv6-x86在ubuntu14.04 i386下正常编译、调试,在ubuntu23.04下编译各种报错--google镜像

来源 原git仓库 xv6-x86(xv6-public) 文档 mit 6.828/2023/ 文档 MIT 6.828/2018/xv6/book-rev11.pdf 原readme 注&#xff1a; xv6-x86(xv6-public) 已经被放弃了, 原作者转向了xv6-riscvxv6-x86文档来源:mit-pdos/xv6-book.git, 它需要 heirloom-doctools 来编译成pdf&#x…

【论文笔记】UniPAD: A Universal Pre-training Paradigm for Autonomous Driving

原文链接&#xff1a;https://arxiv.org/pdf/2310.08370.pdf 1. 引言 过去的3D场景理解预训练方法多采用2D图像领域中的想法&#xff0c;可大致分为基于对比的方法和基于MAE的方法。 基于对比的方法通过对比损失&#xff0c;在特征空间中将相似的3D点拉进而将不相似的点分开…

这些机器视觉工程师犯法了,竟然在闲鱼或淘宝上卖公司的机器视觉程序架构源码

目录 ​从个人层面来讲&#xff1a;从公司层面来讲&#xff1a; ​从个人层面来讲&#xff1a; 个人是法盲&#xff0c;法律意识淡薄只是一方面&#xff0c;另外一个方面就是对于代码的所有权&#xff0c;以及代码的安全性重视不够。把机器视觉程序架构源码打包在闲鱼或淘宝上…

CCF ChinaSoft 2023 论坛巡礼 | NASAC青年软件创新奖论坛

2023年CCF中国软件大会&#xff08;CCF ChinaSoft 2023&#xff09;由CCF主办&#xff0c;CCF系统软件专委会、形式化方法专委会、软件工程专委会以及复旦大学联合承办&#xff0c;将于2023年12月1-3日在上海国际会议中心举行。 本次大会主题是“智能化软件创新推动数字经济与社…

网络服务退出一个问题的解析

一、问题 在实际开发中遇到一个问题&#xff0c;解决的过程虽然不长&#xff0c;但确实是想得比较多&#xff0c;总结一下&#xff0c;以供参考。这是一个网络通信的服务端而且使用的是别人封装好的库&#xff0c;通信等都没有问题&#xff0c;但在退出时会报一个错误&#xf…

云安全—Dashboard 攻击面

0x00 前言 众所周知&#xff0c;如果只是一味的REST接口或者命令行话的操作方式&#xff0c;就会变相的提高操作门款&#xff0c;并且不会有很好的呈现方式&#xff0c;所以就有了web ui的方式&#xff0c;也就是Dashboar面板&#xff0c;本篇主要讨论一下关于Dashboar面板的概…

Vue3使用 xlsx 导出excel 数据

一、安装 xlsx 库 首先&#xff0c;在你的 Vue 3 项目中使用 npm 或 yarn 安装 xlsx 库 npm install xlsx # 或 yarn add xlsx二、创建一个导出 Excel 的方法 在你的 Vue 组件中&#xff0c;创建一个方法来处理数据并导出 Excel。例如&#xff1a; // 引入 xlsx 库 import * …

asp.net人事管理信息系统VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio

一、源码特点 asp.net 人事管理信息系统是一套完善的web设计管理系统&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为vs2010&#xff0c;数据库为sqlserver2008&#xff0c;使用c#语言 开发 asp.net 人事管理系统1 应用技术…

做一个网站可以app封装打包?

app封装打包&#xff0c;有些网站可以打包APP&#xff0c;将网站转换为APP。不同的网站平台和工具可能具有不同的功能和限制&#xff0c;因此app封装打包需要根据具体情况选择适合的平台和工具。 一些网站平台提供了将网站转换为APP的功能&#xff0c;例如HBuilderX、Appgyver…

adb and 软件架构笔记

Native Service&#xff0c;这是Android系统里的一种特色&#xff0c;就是通过C或是C代码写出来的&#xff0c;供Java进行远程调用的Remote Service&#xff0c;因为C/C代码生成的是Native代码&#xff08;机器代码&#xff09;&#xff0c;于是叫Native Service。 native服务…

怎么调整excel表里面所有单元格中,某个相同字体大小,单元格中其他文字大小不变?

环境: excel 2021 python3.8 问题描述: 怎么调整excel表里面所有单元格里面1这个字体大小,单元格里面其他文字不变? excel表里面。很多单元格都有1,1和文字都是10号字体,现在想把全部1字字体调整为16号其他字大小都不变 解决方案: 一、使用python来实现,经过测…