東莞市住房建設(shè)局網(wǎng)站成都百度推廣開(kāi)戶公司
一、ldemul_create_output_section_statements()
位于lang_process()中11行? 。? 該函數(shù)用于創(chuàng)建與目標(biāo)有關(guān)的輸出段的語(yǔ)句。這些語(yǔ)句將用于描述輸出段的屬性和分配。
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 ()
?將命令行中所有未定義的符號(hào)加入哈希表中
結(jié)構(gòu)體類型:
struct bfd_sym_chain
:
- 這是一個(gè)結(jié)構(gòu)體定義,表示符號(hào)鏈的鏈接列表節(jié)點(diǎn)。每個(gè)節(jié)點(diǎn)包含指向下一個(gè)節(jié)點(diǎn)的指針和指向字符字符串的指針(可能是符號(hào)名稱)。
-
typedef struct bfd_sym_chain ldlang_undef_chain_list_type
: - 這行代碼為
struct bfd_sym_chain
創(chuàng)建了類型別名ldlang_undef_chain_list_type
,以便更容易使用和聲明這種類型的變量。 -
#define ldlang_undef_chain_list_head entry_symbol.next
: - 這似乎是一個(gè)預(yù)處理器宏,將
ldlang_undef_chain_list_head
定義為entry_symbol.next
。它可能用作訪問(wèn)符號(hào)鏈節(jié)點(diǎn)的next
字段的簡(jiǎn)寫(xiě)。
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
函數(shù):?
static void lang_place_undefineds(void)
:
- 這是一個(gè)函數(shù)定義的開(kāi)始,名為
lang_place_undefineds
。它是一個(gè)靜態(tài)函數(shù),意味著它僅限于當(dāng)前的翻譯單元。這個(gè)函數(shù)的目的是遍歷未定義符號(hào)(ldlang_undef_chain_list_type
)的列表,并為每個(gè)符號(hào)的名稱調(diào)用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)
:
- 這是另一個(gè)靜態(tài)函數(shù)定義,名為
insert_undefined
。它以字符串(name
)作為參數(shù)。這個(gè)函數(shù)的目的是將未定義符號(hào)插入符號(hào)表中。它首先使用bfd_link_hash_lookup
在哈希表中查找符號(hào),如果找不到,則使用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_lookup
和bfd_hash_lookup
函數(shù):
- 這些函數(shù)用于在哈希表中查找條目。
bfd_link_hash_lookup
似乎用于在符號(hào)哈希表中查找條目,而bfd_hash_lookup
是一個(gè)更一般的哈希表查找函數(shù)。這些函數(shù)通過(guò)對(duì)輸入字符串進(jìn)行哈希并在哈希表中搜索相應(yīng)的條目來(lái)工作。 -
bfd_hash_insert
函數(shù): - 此函數(shù)用于將新條目插入哈希表。它為條目分配內(nèi)存,計(jì)算哈希值,并將條目插入哈希表的適當(dāng)位置。如果需要,它還處理表的大小調(diào)整。
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;
}