mpw-elfmips.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,443 行 · 第 1/4 页
C
1,443 行
/* This file is is generated by a shell script. DO NOT EDIT! *//* 32 bit ELF emulation code for elf32ebmip Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001 Free Software Foundation, Inc. Written by Steve Chamberlain <sac@cygnus.com> ELF support by Ian Lance Taylor <ian@cygnus.com>This file is part of GLD, the Gnu Linker.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#define TARGET_IS_elf32ebmip#include "bfd.h"#include "sysdep.h"#include <ctype.h>#include "bfdlink.h"#include "ld.h"#include "ldmain.h"#include "ldmisc.h"#include "ldexp.h"#include "ldlang.h"#include "ldgram.h"#include "ldfile.h"#include "ldemul.h"static void gldelf32ebmip_before_parse PARAMS ((void));static boolean gldelf32ebmip_open_dynamic_archive PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));static void gldelf32ebmip_after_open PARAMS ((void));static void gldelf32ebmip_check_needed PARAMS ((lang_input_statement_type *));static void gldelf32ebmip_stat_needed PARAMS ((lang_input_statement_type *));static boolean gldelf32ebmip_search_needed PARAMS ((const char *, const char *));static boolean gldelf32ebmip_try_needed PARAMS ((const char *));static void gldelf32ebmip_before_allocation PARAMS ((void));static void gldelf32ebmip_find_statement_assignment PARAMS ((lang_statement_union_type *));static void gldelf32ebmip_find_exp_assignment PARAMS ((etree_type *));static boolean gldelf32ebmip_place_orphan PARAMS ((lang_input_statement_type *, asection *));static void gldelf32ebmip_place_section PARAMS ((lang_statement_union_type *));static char *gldelf32ebmip_get_script PARAMS ((int *isfile));static voidgldelf32ebmip_before_parse(){ ldfile_output_architecture = bfd_arch_mips; config.dynamic_link = true;}/* Try to open a dynamic archive. This is where we know that ELF dynamic libraries have an extension of .so. */static booleangldelf32ebmip_open_dynamic_archive (arch, search, entry) const char *arch; search_dirs_type *search; lang_input_statement_type *entry;{ const char *filename; char *string; if (! entry->is_archive) return false; filename = entry->filename; string = (char *) xmalloc (strlen (search->name) + strlen (filename) + strlen (arch) + sizeof "/lib.so"); sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); if (! ldfile_try_open_bfd (string, entry)) { free (string); return false; } entry->filename = string; /* We have found a dynamic object to include in the link. The ELF backend linker will create a DT_NEEDED entry in the .dynamic section naming this file. If this file includes a DT_SONAME entry, it will be used. Otherwise, the ELF linker will just use the name of the file. For an archive found by searching, like this one, the DT_NEEDED entry should consist of just the name of the file, without the path information used to find it. Note that we only need to do this if we have a dynamic object; an archive will never be referenced by a DT_NEEDED entry. FIXME: This approach--using bfd_elf_set_dt_needed_name--is not very pretty. I haven't been able to think of anything that is pretty, though. */ if (bfd_check_format (entry->the_bfd, bfd_object) && (entry->the_bfd->flags & DYNAMIC) != 0) { char *needed_name; ASSERT (entry->is_archive && entry->search_dirs_flag); needed_name = (char *) xmalloc (strlen (filename) + strlen (arch) + sizeof "lib.so"); sprintf (needed_name, "lib%s%s.so", filename, arch); bfd_elf_set_dt_needed_name (entry->the_bfd, needed_name); } return true;}/* These variables are required to pass information back and forth between after_open and check_needed and stat_needed. */static struct bfd_link_needed_list *global_needed;static struct stat global_stat;static boolean global_found;/* This is called after all the input files have been opened. */static voidgldelf32ebmip_after_open (){ struct bfd_link_needed_list *needed, *l; /* We only need to worry about this when doing a final link. */ if (link_info.relocateable || link_info.shared) return; /* Get the list of files which appear in DT_NEEDED entries in dynamic objects included in the link (often there will be none). For each such file, we want to track down the corresponding library, and include the symbol table in the link. This is what the runtime dynamic linker will do. Tracking the files down here permits one dynamic object to include another without requiring special action by the person doing the link. Note that the needed list can actually grow while we are stepping through this loop. */ needed = bfd_elf_get_needed_list (output_bfd, &link_info); for (l = needed; l != NULL; l = l->next) { struct bfd_link_needed_list *ll; const char *lib_path; size_t len; search_dirs_type *search; /* If we've already seen this file, skip it. */ for (ll = needed; ll != l; ll = ll->next) if (strcmp (ll->name, l->name) == 0) break; if (ll != l) continue; /* See if this file was included in the link explicitly. */ global_needed = l; global_found = false; lang_for_each_input_file (gldelf32ebmip_check_needed); if (global_found) continue; /* We need to find this file and include the symbol table. We want to search for the file in the same way that the dynamic linker will search. That means that we want to use rpath_link, rpath, then the environment variable LD_LIBRARY_PATH (native only), then the linker script LIB_SEARCH_DIRS. We do not search using the -L arguments. */ if (gldelf32ebmip_search_needed (command_line.rpath_link, l->name)) continue; if (gldelf32ebmip_search_needed (command_line.rpath, l->name)) continue; if (command_line.rpath_link == NULL && command_line.rpath == NULL) { lib_path = (const char *) getenv ("LD_RUN_PATH"); if (gldelf32ebmip_search_needed (lib_path, l->name)) continue; } len = strlen (l->name); for (search = search_head; search != NULL; search = search->next) { char *filename; if (search->cmdline) continue; filename = (char *) xmalloc (strlen (search->name) + len + 2); sprintf (filename, "%s/%s", search->name, l->name); if (gldelf32ebmip_try_needed (filename)) break; free (filename); } if (search != NULL) continue; einfo (_("%P: warning: %s, needed by %B, not found\n"), l->name, l->by); }}/* Search for a needed file in a path. */static booleangldelf32ebmip_search_needed (path, name) const char *path; const char *name;{ const char *s; size_t len; if (path == NULL || *path == '\0') return false; len = strlen (name); while (1) { char *filename, *sset; s = strchr (path, ':'); if (s == NULL) s = path + strlen (path); filename = (char *) xmalloc (s - path + len + 2); if (s == path) sset = filename; else { memcpy (filename, path, s - path); filename[s - path] = '/'; sset = filename + (s - path) + 1; } strcpy (sset, name); if (gldelf32ebmip_try_needed (filename)) return true; free (filename); if (*s == '\0') break; path = s + 1; } return false; }/* This function is called for each possible name for a dynamic object named by a DT_NEEDED entry. */static booleangldelf32ebmip_try_needed (name) const char *name;{ bfd *abfd; abfd = bfd_openr (name, bfd_get_target (output_bfd)); if (abfd == NULL) return false; if (! bfd_check_format (abfd, bfd_object)) { (void) bfd_close (abfd); return false; } if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0) { (void) bfd_close (abfd); return false; } /* We've found a dynamic object matching the DT_NEEDED entry. */ /* We have already checked that there is no other input file of the same name. We must now check again that we are not including the same file twice. We need to do this because on many systems libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will reference libc.so.1. If we have already included libc.so, we don't want to include libc.so.1 if they are the same file, and we can only check that using stat. */ if (bfd_stat (abfd, &global_stat) != 0) einfo (_("%F%P:%B: bfd_stat failed: %E\n"), abfd); global_found = false; lang_for_each_input_file (gldelf32ebmip_stat_needed); if (global_found) { /* Return true to indicate that we found the file, even though we aren't going to do anything with it. */ return true; } /* Tell the ELF backend that don't want the output file to have a DT_NEEDED entry for this file. */ bfd_elf_set_dt_needed_name (abfd, ""); /* Add this file into the symbol table. */ if (! bfd_link_add_symbols (abfd, &link_info)) einfo (_("%F%B: could not read symbols: %E\n"), abfd); return true;}/* See if an input file matches a DT_NEEDED entry by name. */static voidgldelf32ebmip_check_needed (s) lang_input_statement_type *s;{ if (global_found) return; if (s->filename != NULL && strcmp (s->filename, global_needed->name) == 0) { global_found = true; return; } if (s->the_bfd != NULL) { const char *soname; soname = bfd_elf_get_dt_soname (s->the_bfd); if (soname != NULL && strcmp (soname, global_needed->name) == 0) { global_found = true; return; } } if (s->search_dirs_flag && s->filename != NULL && strchr (global_needed->name, '/') == NULL) { const char *f; f = strrchr (s->filename, '/'); if (f != NULL && strcmp (f + 1, global_needed->name) == 0) { global_found = true; return;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?