GNU Binutils with patches for OS216
Revision | 5522f910cb539905d6adfdceab208ddfa5e84557 (tree) |
---|---|
Zeit | 2016-04-29 17:24:42 |
Autor | Nick Clifton <nickc@redh...> |
Commiter | Nick Clifton |
Enhance support for copying and stripping Solaris and ARM binaries.
PR 19938
bfd * elf-bfd.h (struct elf_backend_data): Rename
elf_backend_set_special_section_info_and_link to
elf_backend_copy_special_section_fields.
* elfxx-target.h: Likewise.
* elf.c (section_match): Ignore the SHF_INFO_LINK flag when
comparing section flags.
(copy_special_section_fields): New function.
(_bfd_elf_copy_private_bfd_data): Copy the EI_ABIVERSION field.
Perform two scans over special sections. The first one looks for
a direct mapping between the output section and an input section.
The second scan looks for a possible match based upon section
characteristics.
* elf32-arm.c (elf32_arm_copy_special_section_fields): New
function. Handle setting the sh_link field of SHT_ARM_EXIDX
sections.
* elf32-i386.c (elf32_i386_set_special_info_link): Rename to
elf32_i386_copy_solaris_special_section_fields.
* elf32-sparc.c (elf32_sparc_set_special_section_info_link):
Rename to elf32_sparc_copy_solaris_special_section_fields.
* elf64-x86-64.c (elf64_x86_64_set_special_info_link): Rename to
elf64_x86_64_copy_solaris_special_section_fields.
binutils* readelf.c (get_solaris_segment_type): New function.
(get_segment_type): Call it.
@@ -1,3 +1,28 @@ | ||
1 | +2016-04-29 Nick Clifton <nickc@redhat.com> | |
2 | + | |
3 | + PR 19938 | |
4 | + * elf-bfd.h (struct elf_backend_data): Rename | |
5 | + elf_backend_set_special_section_info_and_link to | |
6 | + elf_backend_copy_special_section_fields. | |
7 | + * elfxx-target.h: Likewise. | |
8 | + * elf.c (section_match): Ignore the SHF_INFO_LINK flag when | |
9 | + comparing section flags. | |
10 | + (copy_special_section_fields): New function. | |
11 | + (_bfd_elf_copy_private_bfd_data): Copy the EI_ABIVERSION field. | |
12 | + Perform two scans over special sections. The first one looks for | |
13 | + a direct mapping between the output section and an input section. | |
14 | + The second scan looks for a possible match based upon section | |
15 | + characteristics. | |
16 | + * elf32-arm.c (elf32_arm_copy_special_section_fields): New | |
17 | + function. Handle setting the sh_link field of SHT_ARM_EXIDX | |
18 | + sections. | |
19 | + * elf32-i386.c (elf32_i386_set_special_info_link): Rename to | |
20 | + elf32_i386_copy_solaris_special_section_fields. | |
21 | + * elf32-sparc.c (elf32_sparc_set_special_section_info_link): | |
22 | + Rename to elf32_sparc_copy_solaris_special_section_fields. | |
23 | + * elf64-x86-64.c (elf64_x86_64_set_special_info_link): Rename to | |
24 | + elf64_x86_64_copy_solaris_special_section_fields. | |
25 | + | |
1 | 26 | 2016-04-28 Nick Clifton <nickc@redhat.com> |
2 | 27 | |
3 | 28 | * po/zh_CN.po: Updated Chinese (simplified) translation. |
@@ -1300,13 +1300,15 @@ struct elf_backend_data | ||
1300 | 1300 | /* Return the section which RELOC_SEC applies to. */ |
1301 | 1301 | asection *(*get_reloc_section) (asection *reloc_sec); |
1302 | 1302 | |
1303 | - /* Called when setting the sh_link and sh_info fields of a section with a | |
1304 | - type >= SHT_LOOS. Returns TRUE if these fields were initialised in | |
1305 | - OHEADER, FALSE otherwise. IHEADER is the best guess matching section | |
1306 | - from the input bfd IBFD. */ | |
1307 | - bfd_boolean (*elf_backend_set_special_section_info_and_link) | |
1308 | - (const bfd *ibfd, bfd *obfd, const Elf_Internal_Shdr *iheader, | |
1309 | - Elf_Internal_Shdr *oheader); | |
1303 | + /* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which | |
1304 | + has a type >= SHT_LOOS. Returns TRUE if the fields were initialised, | |
1305 | + FALSE otherwise. Can be called multiple times for a given section, | |
1306 | + until it returns TRUE. Most of the times it is called ISECTION will be | |
1307 | + set to an input section that might be associated with the output section. | |
1308 | + The last time that it is called, ISECTION will be set to NULL. */ | |
1309 | + bfd_boolean (*elf_backend_copy_special_section_fields) | |
1310 | + (const bfd *ibfd, bfd *obfd, const Elf_Internal_Shdr *isection, | |
1311 | + Elf_Internal_Shdr *osection); | |
1310 | 1312 | |
1311 | 1313 | /* Used to handle bad SHF_LINK_ORDER input. */ |
1312 | 1314 | bfd_error_handler_type link_order_error_handler; |
@@ -1218,11 +1218,13 @@ bfd_elf_generic_reloc (bfd *abfd ATTRIBUTE_UNUSED, | ||
1218 | 1218 | should be the same. */ |
1219 | 1219 | |
1220 | 1220 | static bfd_boolean |
1221 | -section_match (Elf_Internal_Shdr * a, Elf_Internal_Shdr * b) | |
1221 | +section_match (const Elf_Internal_Shdr * a, | |
1222 | + const Elf_Internal_Shdr * b) | |
1222 | 1223 | { |
1223 | 1224 | return |
1224 | 1225 | a->sh_type == b->sh_type |
1225 | - && a->sh_flags == b->sh_flags | |
1226 | + && (a->sh_flags & ~ SHF_INFO_LINK) | |
1227 | + == (b->sh_flags & ~ SHF_INFO_LINK) | |
1226 | 1228 | && a->sh_addralign == b->sh_addralign |
1227 | 1229 | && a->sh_size == b->sh_size |
1228 | 1230 | && a->sh_entsize == b->sh_entsize |
@@ -1236,7 +1238,7 @@ section_match (Elf_Internal_Shdr * a, Elf_Internal_Shdr * b) | ||
1236 | 1238 | to be the correct section. */ |
1237 | 1239 | |
1238 | 1240 | static unsigned int |
1239 | -find_link (bfd * obfd, Elf_Internal_Shdr * iheader, unsigned int hint) | |
1241 | +find_link (const bfd * obfd, const Elf_Internal_Shdr * iheader, const unsigned int hint) | |
1240 | 1242 | { |
1241 | 1243 | Elf_Internal_Shdr ** oheaders = elf_elfsections (obfd); |
1242 | 1244 | unsigned int i; |
@@ -1257,14 +1259,110 @@ find_link (bfd * obfd, Elf_Internal_Shdr * iheader, unsigned int hint) | ||
1257 | 1259 | return SHN_UNDEF; |
1258 | 1260 | } |
1259 | 1261 | |
1262 | +/* PR 19938: Attempt to set the ELF section header fields of an OS or | |
1263 | + Processor specific section, based upon a matching input section. | |
1264 | + Returns TRUE upon success, FALSE otherwise. */ | |
1265 | + | |
1266 | +static bfd_boolean | |
1267 | +copy_special_section_fields (const bfd *ibfd, | |
1268 | + bfd *obfd, | |
1269 | + const Elf_Internal_Shdr *iheader, | |
1270 | + Elf_Internal_Shdr *oheader, | |
1271 | + const unsigned int secnum) | |
1272 | +{ | |
1273 | + const struct elf_backend_data *bed = get_elf_backend_data (obfd); | |
1274 | + const Elf_Internal_Shdr **iheaders = (const Elf_Internal_Shdr **) elf_elfsections (ibfd); | |
1275 | + bfd_boolean changed = FALSE; | |
1276 | + unsigned int sh_link; | |
1277 | + | |
1278 | + if (oheader->sh_type == SHT_NOBITS) | |
1279 | + { | |
1280 | + /* This is a feature for objcopy --only-keep-debug: | |
1281 | + When a section's type is changed to NOBITS, we preserve | |
1282 | + the sh_link and sh_info fields so that they can be | |
1283 | + matched up with the original. | |
1284 | + | |
1285 | + Note: Strictly speaking these assignments are wrong. | |
1286 | + The sh_link and sh_info fields should point to the | |
1287 | + relevent sections in the output BFD, which may not be in | |
1288 | + the same location as they were in the input BFD. But | |
1289 | + the whole point of this action is to preserve the | |
1290 | + original values of the sh_link and sh_info fields, so | |
1291 | + that they can be matched up with the section headers in | |
1292 | + the original file. So strictly speaking we may be | |
1293 | + creating an invalid ELF file, but it is only for a file | |
1294 | + that just contains debug info and only for sections | |
1295 | + without any contents. */ | |
1296 | + if (oheader->sh_link == 0) | |
1297 | + oheader->sh_link = iheader->sh_link; | |
1298 | + if (oheader->sh_info == 0) | |
1299 | + oheader->sh_info = iheader->sh_info; | |
1300 | + return TRUE; | |
1301 | + } | |
1302 | + | |
1303 | + /* Allow the target a chance to decide how these fields should be set. */ | |
1304 | + if (bed->elf_backend_copy_special_section_fields != NULL | |
1305 | + && bed->elf_backend_copy_special_section_fields | |
1306 | + (ibfd, obfd, iheader, oheader)) | |
1307 | + return TRUE; | |
1308 | + | |
1309 | + /* We have an iheader which might match oheader, and which has non-zero | |
1310 | + sh_info and/or sh_link fields. Attempt to follow those links and find | |
1311 | + the section in the output bfd which corresponds to the linked section | |
1312 | + in the input bfd. */ | |
1313 | + if (iheader->sh_link != SHN_UNDEF) | |
1314 | + { | |
1315 | + sh_link = find_link (obfd, iheaders[iheader->sh_link], iheader->sh_link); | |
1316 | + if (sh_link != SHN_UNDEF) | |
1317 | + { | |
1318 | + oheader->sh_link = sh_link; | |
1319 | + changed = TRUE; | |
1320 | + } | |
1321 | + else | |
1322 | + /* FIXME: Should we install iheader->sh_link | |
1323 | + if we could not find a match ? */ | |
1324 | + (* _bfd_error_handler) | |
1325 | + (_("%B: Failed to find link section for section %d"), obfd, secnum); | |
1326 | + } | |
1327 | + | |
1328 | + if (iheader->sh_info) | |
1329 | + { | |
1330 | + /* The sh_info field can hold arbitrary information, but if the | |
1331 | + SHF_LINK_INFO flag is set then it should be interpreted as a | |
1332 | + section index. */ | |
1333 | + if (iheader->sh_flags & SHF_INFO_LINK) | |
1334 | + { | |
1335 | + sh_link = find_link (obfd, iheaders[iheader->sh_info], | |
1336 | + iheader->sh_info); | |
1337 | + if (sh_link != SHN_UNDEF) | |
1338 | + oheader->sh_flags |= SHF_INFO_LINK; | |
1339 | + } | |
1340 | + else | |
1341 | + /* No idea what it means - just copy it. */ | |
1342 | + sh_link = iheader->sh_info; | |
1343 | + | |
1344 | + if (sh_link != SHN_UNDEF) | |
1345 | + { | |
1346 | + oheader->sh_info = sh_link; | |
1347 | + changed = TRUE; | |
1348 | + } | |
1349 | + else | |
1350 | + (* _bfd_error_handler) | |
1351 | + (_("%B: Failed to find info section for section %d"), obfd, secnum); | |
1352 | + } | |
1353 | + | |
1354 | + return changed; | |
1355 | +} | |
1356 | + | |
1260 | 1357 | /* Copy the program header and other data from one object module to |
1261 | 1358 | another. */ |
1262 | 1359 | |
1263 | 1360 | bfd_boolean |
1264 | 1361 | _bfd_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
1265 | 1362 | { |
1266 | - Elf_Internal_Shdr ** iheaders = elf_elfsections (ibfd); | |
1267 | - Elf_Internal_Shdr ** oheaders = elf_elfsections (obfd); | |
1363 | + const Elf_Internal_Shdr **iheaders = (const Elf_Internal_Shdr **) elf_elfsections (ibfd); | |
1364 | + Elf_Internal_Shdr **oheaders = elf_elfsections (obfd); | |
1365 | + const struct elf_backend_data *bed; | |
1268 | 1366 | unsigned int i; |
1269 | 1367 | |
1270 | 1368 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
@@ -1283,39 +1381,84 @@ _bfd_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd) | ||
1283 | 1381 | elf_elfheader (obfd)->e_ident[EI_OSABI] = |
1284 | 1382 | elf_elfheader (ibfd)->e_ident[EI_OSABI]; |
1285 | 1383 | |
1384 | + /* If set, copy the EI_ABIVERSION field. */ | |
1385 | + if (elf_elfheader (ibfd)->e_ident[EI_ABIVERSION]) | |
1386 | + elf_elfheader (obfd)->e_ident[EI_ABIVERSION] | |
1387 | + = elf_elfheader (ibfd)->e_ident[EI_ABIVERSION]; | |
1388 | + | |
1286 | 1389 | /* Copy object attributes. */ |
1287 | 1390 | _bfd_elf_copy_obj_attributes (ibfd, obfd); |
1288 | 1391 | |
1289 | 1392 | if (iheaders == NULL || oheaders == NULL) |
1290 | 1393 | return TRUE; |
1291 | 1394 | |
1292 | - /* Possibly copy the sh_info and sh_link fields. */ | |
1395 | + bed = get_elf_backend_data (obfd); | |
1396 | + | |
1397 | + /* Possibly copy other fields in the section header. */ | |
1293 | 1398 | for (i = 1; i < elf_numsections (obfd); i++) |
1294 | 1399 | { |
1295 | 1400 | unsigned int j; |
1296 | 1401 | Elf_Internal_Shdr * oheader = oheaders[i]; |
1297 | 1402 | |
1403 | + /* Ignore ordinary sections. SHT_NOBITS sections are considered however | |
1404 | + because of a special case need for generating separate debug info | |
1405 | + files. See below for more details. */ | |
1298 | 1406 | if (oheader == NULL |
1299 | 1407 | || (oheader->sh_type != SHT_NOBITS |
1300 | - && oheader->sh_type < SHT_LOOS) | |
1301 | - || oheader->sh_size == 0 | |
1408 | + && oheader->sh_type < SHT_LOOS)) | |
1409 | + continue; | |
1410 | + | |
1411 | + /* Ignore empty sections, and sections whose | |
1412 | + fields have already been initialised. */ | |
1413 | + if (oheader->sh_size == 0 | |
1302 | 1414 | || (oheader->sh_info != 0 && oheader->sh_link != 0)) |
1303 | 1415 | continue; |
1304 | 1416 | |
1305 | 1417 | /* Scan for the matching section in the input bfd. |
1306 | - FIXME: We could use something better than a linear scan here. | |
1418 | + First we try for a direct mapping between the input and output sections. */ | |
1419 | + for (j = 1; j < elf_numsections (ibfd); j++) | |
1420 | + { | |
1421 | + const Elf_Internal_Shdr * iheader = iheaders[j]; | |
1422 | + | |
1423 | + if (iheader == NULL) | |
1424 | + continue; | |
1425 | + | |
1426 | + if (oheader->bfd_section != NULL | |
1427 | + && iheader->bfd_section != NULL | |
1428 | + && iheader->bfd_section->output_section != NULL | |
1429 | + && iheader->bfd_section->output_section == oheader->bfd_section) | |
1430 | + { | |
1431 | + /* We have found a connection from the input section to the | |
1432 | + output section. Attempt to copy the header fields. If | |
1433 | + this fails then do not try any further sections - there | |
1434 | + should only be a one-to-one mapping between input and output. */ | |
1435 | + if (! copy_special_section_fields (ibfd, obfd, iheader, oheader, i)) | |
1436 | + j = elf_numsections (ibfd); | |
1437 | + break; | |
1438 | + } | |
1439 | + } | |
1440 | + | |
1441 | + if (j < elf_numsections (ibfd)) | |
1442 | + continue; | |
1443 | + | |
1444 | + /* That failed. So try to deduce the corresponding input section. | |
1307 | 1445 | Unfortunately we cannot compare names as the output string table |
1308 | 1446 | is empty, so instead we check size, address and type. */ |
1309 | 1447 | for (j = 1; j < elf_numsections (ibfd); j++) |
1310 | 1448 | { |
1311 | - Elf_Internal_Shdr * iheader = iheaders[j]; | |
1449 | + const Elf_Internal_Shdr * iheader = iheaders[j]; | |
1450 | + | |
1451 | + if (iheader == NULL) | |
1452 | + continue; | |
1312 | 1453 | |
1313 | - /* Since --only-keep-debug turns all non-debug sections into | |
1454 | + /* Try matching fields in the input section's header. | |
1455 | + Since --only-keep-debug turns all non-debug sections into | |
1314 | 1456 | SHT_NOBITS sections, the output SHT_NOBITS type matches any |
1315 | 1457 | input type. */ |
1316 | 1458 | if ((oheader->sh_type == SHT_NOBITS |
1317 | 1459 | || iheader->sh_type == oheader->sh_type) |
1318 | - && iheader->sh_flags == oheader->sh_flags | |
1460 | + && (iheader->sh_flags & ~ SHF_INFO_LINK) | |
1461 | + == (oheader->sh_flags & ~ SHF_INFO_LINK) | |
1319 | 1462 | && iheader->sh_addralign == oheader->sh_addralign |
1320 | 1463 | && iheader->sh_entsize == oheader->sh_entsize |
1321 | 1464 | && iheader->sh_size == oheader->sh_size |
@@ -1323,99 +1466,18 @@ _bfd_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd) | ||
1323 | 1466 | && (iheader->sh_info != oheader->sh_info |
1324 | 1467 | || iheader->sh_link != oheader->sh_link)) |
1325 | 1468 | { |
1326 | - /* PR 19938: Attempt to preserve the sh_link and sh_info fields | |
1327 | - of OS and Processor specific sections. We try harder for | |
1328 | - these sections, because this is not just about matching | |
1329 | - stripped binaries to their originals. */ | |
1330 | - if (oheader->sh_type >= SHT_LOOS) | |
1331 | - { | |
1332 | - const struct elf_backend_data *bed = get_elf_backend_data (obfd); | |
1333 | - bfd_boolean changed = FALSE; | |
1334 | - unsigned int sh_link; | |
1335 | - | |
1336 | - /* Allow the target a chance to decide how these fields should | |
1337 | - be set. */ | |
1338 | - if (bed->elf_backend_set_special_section_info_and_link != NULL | |
1339 | - && bed->elf_backend_set_special_section_info_and_link | |
1340 | - (ibfd, obfd, iheader, oheader)) | |
1341 | - break; | |
1342 | - | |
1343 | - /* We have iheader which matches oheader, but which has | |
1344 | - non-zero sh_info and/or sh_link fields. Attempt to | |
1345 | - follow those links and find the section in the output | |
1346 | - bfd which corresponds to the linked section in the input | |
1347 | - bfd. */ | |
1348 | - if (iheader->sh_link != SHN_UNDEF) | |
1349 | - { | |
1350 | - sh_link = find_link (obfd, | |
1351 | - iheaders[iheader->sh_link], | |
1352 | - iheader->sh_link); | |
1353 | - if (sh_link != SHN_UNDEF) | |
1354 | - { | |
1355 | - oheader->sh_link = sh_link; | |
1356 | - changed = TRUE; | |
1357 | - } | |
1358 | - else | |
1359 | - /* FIXME: Should we install iheader->sh_link | |
1360 | - if we could not find a match ? */ | |
1361 | - (* _bfd_error_handler) | |
1362 | - (_("%B: Failed to find link section for section %d"), | |
1363 | - obfd, i); | |
1364 | - } | |
1365 | - | |
1366 | - if (iheader->sh_info) | |
1367 | - { | |
1368 | - /* The sh_info field can hold arbitrary information, | |
1369 | - but if the SHF_LINK_INFO flag is set then it | |
1370 | - should be interpreted as a section index. */ | |
1371 | - if (iheader->sh_flags & SHF_INFO_LINK) | |
1372 | - sh_link = find_link (obfd, | |
1373 | - iheaders[iheader->sh_info], | |
1374 | - iheader->sh_info); | |
1375 | - else | |
1376 | - /* No idea what it means - just copy it. */ | |
1377 | - sh_link = iheader->sh_info; | |
1378 | - | |
1379 | - if (sh_link != SHN_UNDEF) | |
1380 | - { | |
1381 | - oheader->sh_info = sh_link; | |
1382 | - changed = TRUE; | |
1383 | - } | |
1384 | - else | |
1385 | - (* _bfd_error_handler) | |
1386 | - (_("%B: Failed to find info section for section %d"), | |
1387 | - obfd, i); | |
1388 | - } | |
1389 | - | |
1390 | - if (changed) | |
1391 | - break; | |
1392 | - } | |
1393 | - else | |
1394 | - { | |
1395 | - /* This is an feature for objcopy --only-keep-debug: | |
1396 | - When a section's type is changed to NOBITS, we preserve | |
1397 | - the sh_link and sh_info fields so that they can be | |
1398 | - matched up with the original. | |
1399 | - | |
1400 | - Note: Strictly speaking these assignments are wrong. | |
1401 | - The sh_link and sh_info fields should point to the | |
1402 | - relevent sections in the output BFD, which may not be in | |
1403 | - the same location as they were in the input BFD. But | |
1404 | - the whole point of this action is to preserve the | |
1405 | - original values of the sh_link and sh_info fields, so | |
1406 | - that they can be matched up with the section headers in | |
1407 | - the original file. So strictly speaking we may be | |
1408 | - creating an invalid ELF file, but it is only for a file | |
1409 | - that just contains debug info and only for sections | |
1410 | - without any contents. */ | |
1411 | - if (oheader->sh_link == 0) | |
1412 | - oheader->sh_link = iheader->sh_link; | |
1413 | - if (oheader->sh_info == 0) | |
1414 | - oheader->sh_info = iheader->sh_info; | |
1415 | - break; | |
1416 | - } | |
1469 | + if (copy_special_section_fields (ibfd, obfd, iheader, oheader, i)) | |
1470 | + break; | |
1417 | 1471 | } |
1418 | 1472 | } |
1473 | + | |
1474 | + if (j == elf_numsections (ibfd) && oheader->sh_type >= SHT_LOOS) | |
1475 | + { | |
1476 | + /* Final attempt. Call the backend copy function | |
1477 | + with a NULL input section. */ | |
1478 | + if (bed->elf_backend_copy_special_section_fields != NULL) | |
1479 | + bed->elf_backend_copy_special_section_fields (ibfd, obfd, NULL, oheader); | |
1480 | + } | |
1419 | 1481 | } |
1420 | 1482 | |
1421 | 1483 | return TRUE; |
@@ -14112,11 +14112,15 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, | ||
14112 | 14112 | s = bfd_get_linker_section (dynobj, ".dynbss"); |
14113 | 14113 | BFD_ASSERT (s != NULL); |
14114 | 14114 | |
14115 | - /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to | |
14116 | - copy the initial value out of the dynamic object and into the | |
14117 | - runtime process image. We need to remember the offset into the | |
14115 | + /* If allowed, we must generate a R_ARM_COPY reloc to tell the dynamic | |
14116 | + linker to copy the initial value out of the dynamic object and into | |
14117 | + the runtime process image. We need to remember the offset into the | |
14118 | 14118 | .rel(a).bss section we are going to use. */ |
14119 | - if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) | |
14119 | + if (info->nocopyreloc == 0 | |
14120 | + && (h->root.u.def.section->flags & SEC_ALLOC) != 0 | |
14121 | + /* PR 16177: A copy is only needed if the input section is readonly. */ | |
14122 | + && (h->root.u.def.section->flags & SEC_READONLY) == 0 | |
14123 | + && h->size != 0) | |
14120 | 14124 | { |
14121 | 14125 | asection *srel; |
14122 | 14126 |
@@ -17873,6 +17877,100 @@ elf32_arm_count_additional_relocs (asection *sec) | ||
17873 | 17877 | return arm_data->additional_reloc_count; |
17874 | 17878 | } |
17875 | 17879 | |
17880 | +/* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which | |
17881 | + has a type >= SHT_LOOS. Returns TRUE if these fields were initialised | |
17882 | + FALSE otherwise. ISECTION is the best guess matching section from the | |
17883 | + input bfd IBFD, but it might be NULL. */ | |
17884 | + | |
17885 | +static bfd_boolean | |
17886 | +elf32_arm_copy_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED, | |
17887 | + bfd *obfd ATTRIBUTE_UNUSED, | |
17888 | + const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
17889 | + Elf_Internal_Shdr *osection) | |
17890 | +{ | |
17891 | + switch (osection->sh_type) | |
17892 | + { | |
17893 | + case SHT_ARM_EXIDX: | |
17894 | + { | |
17895 | + Elf_Internal_Shdr **oheaders = elf_elfsections (obfd); | |
17896 | + Elf_Internal_Shdr **iheaders = elf_elfsections (ibfd); | |
17897 | + unsigned i = 0; | |
17898 | + | |
17899 | + osection->sh_flags = SHF_ALLOC | SHF_LINK_ORDER; | |
17900 | + osection->sh_info = 0; | |
17901 | + | |
17902 | + /* The sh_link field must be set to the text section associated with | |
17903 | + this index section. Unfortunately the ARM EHABI does not specify | |
17904 | + exactly how to determine this association. Our caller does try | |
17905 | + to match up OSECTION with its corresponding input section however | |
17906 | + so that is a good first guess. */ | |
17907 | + if (isection != NULL | |
17908 | + && osection->bfd_section != NULL | |
17909 | + && isection->bfd_section != NULL | |
17910 | + && isection->bfd_section->output_section != NULL | |
17911 | + && isection->bfd_section->output_section == osection->bfd_section | |
17912 | + && iheaders != NULL | |
17913 | + && isection->sh_link > 0 | |
17914 | + && isection->sh_link < elf_numsections (ibfd) | |
17915 | + && iheaders[isection->sh_link]->bfd_section != NULL | |
17916 | + && iheaders[isection->sh_link]->bfd_section->output_section != NULL | |
17917 | + ) | |
17918 | + { | |
17919 | + for (i = elf_numsections (obfd); i-- > 0;) | |
17920 | + if (oheaders[i]->bfd_section | |
17921 | + == iheaders[isection->sh_link]->bfd_section->output_section) | |
17922 | + break; | |
17923 | + } | |
17924 | + | |
17925 | + if (i == 0) | |
17926 | + { | |
17927 | + /* Failing that we have to find a matching section ourselves. If | |
17928 | + we had the output section name available we could compare that | |
17929 | + with input section names. Unfortunately we don't. So instead | |
17930 | + we use a simple heuristic and look for the nearest executable | |
17931 | + section before this one. */ | |
17932 | + for (i = elf_numsections (obfd); i-- > 0;) | |
17933 | + if (oheaders[i] == osection) | |
17934 | + break; | |
17935 | + if (i == 0) | |
17936 | + break; | |
17937 | + | |
17938 | + while (i-- > 0) | |
17939 | + if (oheaders[i]->sh_type == SHT_PROGBITS | |
17940 | + && (oheaders[i]->sh_flags & (SHF_ALLOC | SHF_EXECINSTR)) | |
17941 | + == (SHF_ALLOC | SHF_EXECINSTR)) | |
17942 | + break; | |
17943 | + } | |
17944 | + | |
17945 | + if (i) | |
17946 | + { | |
17947 | + osection->sh_link = i; | |
17948 | + /* If the text section was part of a group | |
17949 | + then the index section should be too. */ | |
17950 | + if (oheaders[i]->sh_flags & SHF_GROUP) | |
17951 | + osection->sh_flags |= SHF_GROUP; | |
17952 | + return TRUE; | |
17953 | + } | |
17954 | + } | |
17955 | + break; | |
17956 | + | |
17957 | + case SHT_ARM_PREEMPTMAP: | |
17958 | + osection->sh_flags = SHF_ALLOC; | |
17959 | + break; | |
17960 | + | |
17961 | + case SHT_ARM_ATTRIBUTES: | |
17962 | + case SHT_ARM_DEBUGOVERLAY: | |
17963 | + case SHT_ARM_OVERLAYSECTION: | |
17964 | + default: | |
17965 | + break; | |
17966 | + } | |
17967 | + | |
17968 | + return FALSE; | |
17969 | +} | |
17970 | + | |
17971 | +#undef elf_backend_copy_special_section_fields | |
17972 | +#define elf_backend_copy_special_section_fields elf32_arm_copy_special_section_fields | |
17973 | + | |
17876 | 17974 | #define ELF_ARCH bfd_arch_arm |
17877 | 17975 | #define ELF_TARGET_ID ARM_ELF_DATA |
17878 | 17976 | #define ELF_MACHINE_CODE EM_ARM |
@@ -18035,6 +18133,7 @@ elf32_arm_nacl_plt_sym_val (bfd_vma i, const asection *plt, | ||
18035 | 18133 | #undef bfd_elf32_get_synthetic_symtab |
18036 | 18134 | #undef elf_backend_plt_sym_val |
18037 | 18135 | #define elf_backend_plt_sym_val elf32_arm_nacl_plt_sym_val |
18136 | +#undef elf_backend_copy_special_section_fields | |
18038 | 18137 | |
18039 | 18138 | #undef ELF_MINPAGESIZE |
18040 | 18139 | #undef ELF_COMMONPAGESIZE |
@@ -18454,7 +18553,6 @@ elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt, | ||
18454 | 18553 | return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i; |
18455 | 18554 | } |
18456 | 18555 | |
18457 | - | |
18458 | 18556 | #undef elf32_bed |
18459 | 18557 | #define elf32_bed elf32_arm_symbian_bed |
18460 | 18558 |
@@ -5905,16 +5905,22 @@ elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info) | ||
5905 | 5905 | #undef elf_backend_strtab_flags |
5906 | 5906 | #define elf_backend_strtab_flags SHF_STRINGS |
5907 | 5907 | |
5908 | +/* Called to set the sh_flags, sh_link and sh_info fields of OSECTION which | |
5909 | + has a type >= SHT_LOOS. Returns TRUE if these fields were initialised | |
5910 | + FALSE otherwise. ISECTION is the best guess matching section from the | |
5911 | + input bfd IBFD, but it might be NULL. */ | |
5912 | + | |
5908 | 5913 | static bfd_boolean |
5909 | -elf32_i386_set_special_info_link (const bfd *ibfd ATTRIBUTE_UNUSED, | |
5910 | - bfd *obfd ATTRIBUTE_UNUSED, | |
5911 | - const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
5912 | - Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
5914 | +elf32_i386_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED, | |
5915 | + bfd *obfd ATTRIBUTE_UNUSED, | |
5916 | + const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
5917 | + Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
5913 | 5918 | { |
5914 | 5919 | /* PR 19938: FIXME: Need to add code for setting the sh_info |
5915 | - and sh_link fields of Solaris specific section types. | |
5920 | + and sh_link fields of Solaris specific section types. */ | |
5921 | + return FALSE; | |
5916 | 5922 | |
5917 | - Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13, | |
5923 | + /* Based upon Oracle Solaris 11.3 Linkers and Libraries Guide, Ch. 13, | |
5918 | 5924 | Object File Format, Table 13-9 ELF sh_link and sh_info Interpretation: |
5919 | 5925 | |
5920 | 5926 | http://docs.oracle.com/cd/E53394_01/html/E54813/chapter6-94076.html#scrolltoc |
@@ -5974,11 +5980,10 @@ SHT_SUNW_verneed The section header index of The number of version | ||
5974 | 5980 | |
5975 | 5981 | SHT_SUNW_versym The section header index of 0 |
5976 | 5982 | [0x6fffffff] the associated symbol table. */ |
5977 | - return FALSE; | |
5978 | 5983 | } |
5979 | 5984 | |
5980 | -#undef elf_backend_set_special_section_info_and_link | |
5981 | -#define elf_backend_set_special_section_info_and_link elf32_i386_set_special_info_link | |
5985 | +#undef elf_backend_copy_special_section_fields | |
5986 | +#define elf_backend_copy_special_section_fields elf32_i386_copy_solaris_special_section_fields | |
5982 | 5987 | |
5983 | 5988 | #include "elf32-target.h" |
5984 | 5989 |
@@ -6016,7 +6021,7 @@ elf32_iamcu_elf_object_p (bfd *abfd) | ||
6016 | 6021 | #define elf_backend_want_plt_sym 0 |
6017 | 6022 | |
6018 | 6023 | #undef elf_backend_strtab_flags |
6019 | -#undef elf_backend_set_special_section_info_and_link | |
6024 | +#undef elf_backend_copy_special_section_fields | |
6020 | 6025 | |
6021 | 6026 | #include "elf32-target.h" |
6022 | 6027 |
@@ -265,18 +265,18 @@ elf32_sparc_add_symbol_hook (bfd * abfd, | ||
265 | 265 | #define elf_backend_strtab_flags SHF_STRINGS |
266 | 266 | |
267 | 267 | static bfd_boolean |
268 | -elf32_sparc_set_special_info_link (const bfd *ibfd ATTRIBUTE_UNUSED, | |
269 | - bfd *obfd ATTRIBUTE_UNUSED, | |
270 | - const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
271 | - Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
268 | +elf32_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED, | |
269 | + bfd *obfd ATTRIBUTE_UNUSED, | |
270 | + const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
271 | + Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
272 | 272 | { |
273 | 273 | /* PR 19938: FIXME: Need to add code for setting the sh_info |
274 | 274 | and sh_link fields of Solaris specific section types. */ |
275 | 275 | return FALSE; |
276 | 276 | } |
277 | 277 | |
278 | -#undef elf_backend_set_special_section_info_and_link | |
279 | -#define elf_backend_set_special_section_info_and_link elf32_sparc_set_special_info_link | |
278 | +#undef elf_backend_copy_special_section_fields | |
279 | +#define elf_backend_copy_special_section_fields elf32_sparc_copy_solaris_special_section_fields | |
280 | 280 | |
281 | 281 | #include "elf32-target.h" |
282 | 282 |
@@ -341,7 +341,7 @@ elf32_sparc_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | ||
341 | 341 | elf32_sparc_vxworks_final_write_processing |
342 | 342 | #undef elf_backend_static_tls_alignment |
343 | 343 | #undef elf_backend_strtab_flags |
344 | -#undef elf_backend_set_special_section_info_and_link | |
344 | +#undef elf_backend_copy_special_section_fields | |
345 | 345 | |
346 | 346 | #undef elf32_bed |
347 | 347 | #define elf32_bed sparc_elf_vxworks_bed |
@@ -6552,18 +6552,18 @@ static const struct bfd_elf_special_section | ||
6552 | 6552 | #define elf_backend_strtab_flags SHF_STRINGS |
6553 | 6553 | |
6554 | 6554 | static bfd_boolean |
6555 | -elf64_x86_64_set_special_info_link (const bfd *ibfd ATTRIBUTE_UNUSED, | |
6556 | - bfd *obfd ATTRIBUTE_UNUSED, | |
6557 | - const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
6558 | - Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
6555 | +elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED, | |
6556 | + bfd *obfd ATTRIBUTE_UNUSED, | |
6557 | + const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
6558 | + Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
6559 | 6559 | { |
6560 | 6560 | /* PR 19938: FIXME: Need to add code for setting the sh_info |
6561 | 6561 | and sh_link fields of Solaris specific section types. */ |
6562 | 6562 | return FALSE; |
6563 | 6563 | } |
6564 | 6564 | |
6565 | -#undef elf_backend_set_special_section_info_and_link | |
6566 | -#define elf_backend_set_special_section_info_and_link elf64_x86_64_set_special_info_link | |
6565 | +#undef elf_backend_copy_special_section_fields | |
6566 | +#define elf_backend_copy_special_section_fields elf64_x86_64_copy_solaris_special_section_fields | |
6567 | 6567 | |
6568 | 6568 | #include "elf64-target.h" |
6569 | 6569 |
@@ -6597,7 +6597,7 @@ elf64_x86_64_nacl_elf_object_p (bfd *abfd) | ||
6597 | 6597 | #undef elf_backend_want_plt_sym |
6598 | 6598 | #define elf_backend_want_plt_sym 0 |
6599 | 6599 | #undef elf_backend_strtab_flags |
6600 | -#undef elf_backend_set_special_section_info_and_link | |
6600 | +#undef elf_backend_copy_special_section_fields | |
6601 | 6601 | |
6602 | 6602 | /* NaCl uses substantially different PLT entries for the same effects. */ |
6603 | 6603 |
@@ -686,8 +686,8 @@ | ||
686 | 686 | #define elf_backend_get_reloc_section _bfd_elf_get_reloc_section |
687 | 687 | #endif |
688 | 688 | |
689 | -#ifndef elf_backend_set_special_section_info_and_link | |
690 | -#define elf_backend_set_special_section_info_and_link NULL | |
689 | +#ifndef elf_backend_copy_special_section_fields | |
690 | +#define elf_backend_copy_special_section_fields NULL | |
691 | 691 | #endif |
692 | 692 | |
693 | 693 | #ifndef elf_backend_compact_eh_encoding |
@@ -797,7 +797,7 @@ static struct elf_backend_data elfNN_bed = | ||
797 | 797 | elf_backend_is_function_type, |
798 | 798 | elf_backend_maybe_function_sym, |
799 | 799 | elf_backend_get_reloc_section, |
800 | - elf_backend_set_special_section_info_and_link, | |
800 | + elf_backend_copy_special_section_fields, | |
801 | 801 | elf_backend_link_order_error_handler, |
802 | 802 | elf_backend_relplt_name, |
803 | 803 | ELF_MACHINE_ALT1, |
@@ -1,3 +1,9 @@ | ||
1 | +2016-04-29 Nick Clifton <nickc@redhat.com> | |
2 | + | |
3 | + PR 19938 | |
4 | + * readelf.c (get_solaris_segment_type): New function. | |
5 | + (get_segment_type): Call it. | |
6 | + | |
1 | 7 | 2016-04-28 Nick Clifton <nickc@redhat.com> |
2 | 8 | |
3 | 9 | * po/zh_CN.po: Updated Chinese (simplified) translation. |
@@ -3689,6 +3689,23 @@ get_tic6x_segment_type (unsigned long type) | ||
3689 | 3689 | } |
3690 | 3690 | |
3691 | 3691 | static const char * |
3692 | +get_solaris_segment_type (unsigned long type) | |
3693 | +{ | |
3694 | + switch (type) | |
3695 | + { | |
3696 | + case 0x6464e550: return "PT_SUNW_UNWIND"; | |
3697 | + case 0x6474e550: return "PT_SUNW_EH_FRAME"; | |
3698 | + case 0x6ffffff7: return "PT_LOSUNW"; | |
3699 | + case 0x6ffffffa: return "PT_SUNWBSS"; | |
3700 | + case 0x6ffffffb: return "PT_SUNWSTACK"; | |
3701 | + case 0x6ffffffc: return "PT_SUNWDTRACE"; | |
3702 | + case 0x6ffffffd: return "PT_SUNWCAP"; | |
3703 | + case 0x6fffffff: return "PT_HISUNW"; | |
3704 | + default: return NULL; | |
3705 | + } | |
3706 | +} | |
3707 | + | |
3708 | +static const char * | |
3692 | 3709 | get_segment_type (unsigned long p_type) |
3693 | 3710 | { |
3694 | 3711 | static char buff[32]; |
@@ -3758,7 +3775,10 @@ get_segment_type (unsigned long p_type) | ||
3758 | 3775 | result = get_ia64_segment_type (p_type); |
3759 | 3776 | break; |
3760 | 3777 | default: |
3761 | - result = NULL; | |
3778 | + if (elf_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) | |
3779 | + result = get_solaris_segment_type (p_type); | |
3780 | + else | |
3781 | + result = NULL; | |
3762 | 3782 | break; |
3763 | 3783 | } |
3764 | 3784 |