Subversion Repositories Kolibri OS

Rev

Rev 5197 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5197 Rev 6324
Line 1... Line 1...
1
/* Generic symbol-table support for the BFD library.
1
/* Generic symbol-table support for the BFD library.
2
   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-
 
3
   2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2012
-
 
4
   Free Software Foundation, Inc.
2
   Copyright (C) 1990-2015 Free Software Foundation, Inc.
5
   Written by Cygnus Support.
3
   Written by Cygnus Support.
Line 6... Line 4...
6
 
4
 
Line 7... Line 5...
7
   This file is part of BFD, the Binary File Descriptor library.
5
   This file is part of BFD, the Binary File Descriptor library.
Line 823... Line 821...
823
  if (symcount < 0)
821
  if (symcount < 0)
824
    goto error_return;
822
    goto error_return;
Line 825... Line 823...
825
 
823
 
826
  *minisymsp = syms;
824
  *minisymsp = syms;
-
 
825
  *sizep = sizeof (asymbol *);
827
  *sizep = sizeof (asymbol *);
826
 
Line 828... Line 827...
828
  return symcount;
827
  return symcount;
829
 
828
 
830
 error_return:
829
 error_return:
Line 932... Line 931...
932
				     void **pinfo)
931
				     void **pinfo)
933
{
932
{
934
  struct stab_find_info *info;
933
  struct stab_find_info *info;
935
  bfd_size_type stabsize, strsize;
934
  bfd_size_type stabsize, strsize;
936
  bfd_byte *stab, *str;
935
  bfd_byte *stab, *str;
937
  bfd_byte *last_stab, *last_str;
936
  bfd_byte *nul_fun, *nul_str;
938
  bfd_size_type stroff;
937
  bfd_size_type stroff;
939
  struct indexentry *indexentry;
938
  struct indexentry *indexentry;
940
  char *file_name;
939
  char *file_name;
941
  char *directory_name;
940
  char *directory_name;
942
  int saw_fun;
-
 
943
  bfd_boolean saw_line, saw_func;
941
  bfd_boolean saw_line, saw_func;
Line 944... Line 942...
944
 
942
 
945
  *pfound = FALSE;
943
  *pfound = FALSE;
946
  *pfilename = bfd_get_filename (abfd);
944
  *pfilename = bfd_get_filename (abfd);
Line 986... Line 984...
986
  else
984
  else
987
    {
985
    {
988
      long reloc_size, reloc_count;
986
      long reloc_size, reloc_count;
989
      arelent **reloc_vector;
987
      arelent **reloc_vector;
990
      int i;
988
      int i;
991
      char *name;
-
 
992
      char *function_name;
989
      char *function_name;
993
      bfd_size_type amt = sizeof *info;
990
      bfd_size_type amt = sizeof *info;
Line 994... Line 991...
994
 
991
 
995
      info = (struct stab_find_info *) bfd_zalloc (abfd, amt);
992
      info = (struct stab_find_info *) bfd_zalloc (abfd, amt);
Line 1019... Line 1016...
1019
	}
1016
	}
Line 1020... Line 1017...
1020
 
1017
 
1021
      stabsize = (info->stabsec->rawsize
1018
      stabsize = (info->stabsec->rawsize
1022
		  ? info->stabsec->rawsize
1019
		  ? info->stabsec->rawsize
-
 
1020
		  : info->stabsec->size);
1023
		  : info->stabsec->size);
1021
      stabsize = (stabsize / STABSIZE) * STABSIZE;
1024
      strsize = (info->strsec->rawsize
1022
      strsize = (info->strsec->rawsize
1025
		 ? info->strsec->rawsize
1023
		 ? info->strsec->rawsize
Line 1026... Line 1024...
1026
		 : info->strsec->size);
1024
		 : info->strsec->size);
Line 1100... Line 1098...
1100
	 VM address.  Do this in two passes: once to count how many
1098
	 VM address.  Do this in two passes: once to count how many
1101
	 table entries we'll need, and a second to actually build the
1099
	 table entries we'll need, and a second to actually build the
1102
	 table.  */
1100
	 table.  */
Line 1103... Line 1101...
1103
 
1101
 
1104
      info->indextablesize = 0;
1102
      info->indextablesize = 0;
1105
      saw_fun = 1;
1103
      nul_fun = NULL;
1106
      for (stab = info->stabs; stab < info->stabs + stabsize; stab += STABSIZE)
1104
      for (stab = info->stabs; stab < info->stabs + stabsize; stab += STABSIZE)
1107
	{
1105
	{
1108
	  if (stab[TYPEOFF] == (bfd_byte) N_SO)
1106
	  if (stab[TYPEOFF] == (bfd_byte) N_SO)
1109
	    {
-
 
1110
	      /* N_SO with null name indicates EOF */
-
 
1111
	      if (bfd_get_32 (abfd, stab + STRDXOFF) == 0)
-
 
1112
		continue;
-
 
1113
 
1107
	    {
1114
	      /* if we did not see a function def, leave space for one.  */
1108
	      /* if we did not see a function def, leave space for one.  */
1115
	      if (saw_fun == 0)
1109
	      if (nul_fun != NULL)
Line -... Line 1110...
-
 
1110
		++info->indextablesize;
-
 
1111
 
-
 
1112
	      /* N_SO with null name indicates EOF */
-
 
1113
	      if (bfd_get_32 (abfd, stab + STRDXOFF) == 0)
-
 
1114
		nul_fun = NULL;
1116
		++info->indextablesize;
1115
	      else
Line 1117... Line 1116...
1117
 
1116
		{
1118
	      saw_fun = 0;
1117
		  nul_fun = stab;
1119
 
1118
 
1120
	      /* two N_SO's in a row is a filename and directory. Skip */
-
 
1121
	      if (stab + STABSIZE < info->stabs + stabsize
1119
	      /* two N_SO's in a row is a filename and directory. Skip */
1122
		  && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO)
1120
		  if (stab + STABSIZE + TYPEOFF < info->stabs + stabsize
1123
		{
1121
		  && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO)
1124
		  stab += STABSIZE;
1122
		  stab += STABSIZE;
-
 
1123
		}
1125
		}
1124
	    }
1126
	    }
1125
	  else if (stab[TYPEOFF] == (bfd_byte) N_FUN
1127
	  else if (stab[TYPEOFF] == (bfd_byte) N_FUN)
1126
		   && bfd_get_32 (abfd, stab + STRDXOFF) != 0)
1128
	    {
1127
	    {
1129
	      saw_fun = 1;
1128
	      nul_fun = NULL;
Line 1130... Line 1129...
1130
	      ++info->indextablesize;
1129
	      ++info->indextablesize;
1131
	    }
1130
	    }
Line 1132... Line 1131...
1132
	}
1131
	}
1133
 
1132
 
1134
      if (saw_fun == 0)
1133
      if (nul_fun != NULL)
Line 1144... Line 1143...
1144
      if (info->indextable == NULL)
1143
      if (info->indextable == NULL)
1145
	return FALSE;
1144
	return FALSE;
Line 1146... Line 1145...
1146
 
1145
 
1147
      file_name = NULL;
1146
      file_name = NULL;
1148
      directory_name = NULL;
1147
      directory_name = NULL;
1149
      saw_fun = 1;
1148
      nul_fun = NULL;
Line 1150... Line 1149...
1150
      stroff = 0;
1149
      stroff = 0;
1151
 
1150
 
1152
      for (i = 0, last_stab = stab = info->stabs, last_str = str = info->strs;
1151
      for (i = 0, stab = info->stabs, nul_str = str = info->strs;
1153
	   i < info->indextablesize && stab < info->stabs + stabsize;
1152
	   i < info->indextablesize && stab < info->stabs + stabsize;
1154
	   stab += STABSIZE)
1153
	   stab += STABSIZE)
1155
	{
1154
	{
Line 1169... Line 1168...
1169
	      /* The following code creates a new indextable entry with
1168
	      /* The following code creates a new indextable entry with
1170
	         a NULL function name if there were no N_FUNs in a file.
1169
	         a NULL function name if there were no N_FUNs in a file.
1171
	         Note that a N_SO without a file name is an EOF and
1170
	         Note that a N_SO without a file name is an EOF and
1172
	         there could be 2 N_SO following it with the new filename
1171
	         there could be 2 N_SO following it with the new filename
1173
	         and directory.  */
1172
	         and directory.  */
1174
	      if (saw_fun == 0)
1173
	      if (nul_fun != NULL)
1175
		{
1174
		{
1176
		  info->indextable[i].val = bfd_get_32 (abfd, last_stab + VALOFF);
1175
		  info->indextable[i].val = bfd_get_32 (abfd, nul_fun + VALOFF);
1177
		  info->indextable[i].stab = last_stab;
1176
		  info->indextable[i].stab = nul_fun;
1178
		  info->indextable[i].str = last_str;
1177
		  info->indextable[i].str = nul_str;
1179
		  info->indextable[i].directory_name = directory_name;
1178
		  info->indextable[i].directory_name = directory_name;
1180
		  info->indextable[i].file_name = file_name;
1179
		  info->indextable[i].file_name = file_name;
1181
		  info->indextable[i].function_name = NULL;
1180
		  info->indextable[i].function_name = NULL;
1182
		  ++i;
1181
		  ++i;
1183
		}
1182
		}
1184
	      saw_fun = 0;
-
 
Line -... Line 1183...
-
 
1183
 
1185
 
1184
	      directory_name = NULL;
1186
	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
1185
	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
1187
	      if (*file_name == '\0')
1186
	      if (file_name == (char *) str)
1188
		{
-
 
1189
		  directory_name = NULL;
1187
		{
1190
		  file_name = NULL;
1188
		  file_name = NULL;
1191
		  saw_fun = 1;
1189
		  nul_fun = NULL;
1192
		}
1190
		}
1193
	      else
1191
	      else
1194
		{
1192
		{
1195
		  last_stab = stab;
1193
		  nul_fun = stab;
-
 
1194
		  nul_str = str;
-
 
1195
		  if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
1196
		  last_str = str;
1196
		    file_name = NULL;
1197
		  if (stab + STABSIZE >= info->stabs + stabsize
1197
		  if (stab + STABSIZE + TYPEOFF < info->stabs + stabsize
1198
		      || *(stab + STABSIZE + TYPEOFF) != (bfd_byte) N_SO)
-
 
1199
		    {
-
 
1200
		      directory_name = NULL;
-
 
1201
		    }
-
 
1202
		  else
1198
		      && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO)
1203
		    {
1199
		    {
1204
		      /* Two consecutive N_SOs are a directory and a
1200
		      /* Two consecutive N_SOs are a directory and a
1205
			 file name.  */
1201
			 file name.  */
1206
		      stab += STABSIZE;
1202
		      stab += STABSIZE;
1207
		      directory_name = file_name;
1203
		      directory_name = file_name;
1208
		      file_name = ((char *) str
1204
		      file_name = ((char *) str
-
 
1205
				   + bfd_get_32 (abfd, stab + STRDXOFF));
-
 
1206
		      if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
1209
				   + bfd_get_32 (abfd, stab + STRDXOFF));
1207
			file_name = NULL;
1210
		    }
1208
		    }
1211
		}
1209
		}
Line 1212... Line 1210...
1212
	      break;
1210
	      break;
1213
 
1211
 
1214
	    case N_SOL:
1212
	    case N_SOL:
-
 
1213
	      /* The name of an include file.  */
-
 
1214
	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
-
 
1215
	      /* PR 17512: file: 0c680a1f.  */
-
 
1216
	      /* PR 17512: file: 5da8aec4.  */
1215
	      /* The name of an include file.  */
1217
	      if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
Line 1216... Line 1218...
1216
	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
1218
		file_name = NULL;
1217
	      break;
1219
	      break;
1218
 
-
 
1219
	    case N_FUN:
1220
 
1220
	      /* A function name.  */
-
 
1221
	      saw_fun = 1;
-
 
1222
	      name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
-
 
1223
 
-
 
1224
	      if (*name == '\0')
1221
	    case N_FUN:
1225
		name = NULL;
-
 
1226
 
-
 
1227
	      function_name = name;
1222
	      /* A function name.  */
-
 
1223
	      function_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
-
 
1224
	      if (function_name == (char *) str)
Line -... Line 1225...
-
 
1225
		continue;
1228
 
1226
	      if (function_name >= (char *) info->strs + strsize)
1229
	      if (name == NULL)
1227
		function_name = NULL;
1230
		continue;
1228
 
1231
 
1229
	      nul_fun = NULL;
1232
	      info->indextable[i].val = bfd_get_32 (abfd, stab + VALOFF);
1230
	      info->indextable[i].val = bfd_get_32 (abfd, stab + VALOFF);
Line 1238... Line 1236...
1238
	      ++i;
1236
	      ++i;
1239
	      break;
1237
	      break;
1240
	    }
1238
	    }
1241
	}
1239
	}
Line 1242... Line 1240...
1242
 
1240
 
1243
      if (saw_fun == 0)
1241
      if (nul_fun != NULL)
1244
	{
1242
	{
1245
	  info->indextable[i].val = bfd_get_32 (abfd, last_stab + VALOFF);
1243
	  info->indextable[i].val = bfd_get_32 (abfd, nul_fun + VALOFF);
1246
	  info->indextable[i].stab = last_stab;
1244
	  info->indextable[i].stab = nul_fun;
1247
	  info->indextable[i].str = last_str;
1245
	  info->indextable[i].str = nul_str;
1248
	  info->indextable[i].directory_name = directory_name;
1246
	  info->indextable[i].directory_name = directory_name;
1249
	  info->indextable[i].file_name = file_name;
1247
	  info->indextable[i].file_name = file_name;
1250
	  info->indextable[i].function_name = NULL;
1248
	  info->indextable[i].function_name = NULL;
1251
	  ++i;
1249
	  ++i;
Line 1332... Line 1330...
1332
	  /* The name of an include file.  */
1330
	  /* The name of an include file.  */
1333
	  val = bfd_get_32 (abfd, stab + VALOFF);
1331
	  val = bfd_get_32 (abfd, stab + VALOFF);
1334
	  if (val <= offset)
1332
	  if (val <= offset)
1335
	    {
1333
	    {
1336
	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
1334
	      file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF);
-
 
1335
	      if (file_name >= (char *) info->strs + strsize || file_name < (char *) str)
-
 
1336
		file_name = NULL;
1337
	      *pline = 0;
1337
	      *pline = 0;
1338
	    }
1338
	    }
1339
	  break;
1339
	  break;
Line 1340... Line 1340...
1340
 
1340