Skip to content

Commit d024f85

Browse files
author
duke
committedJul 16, 2020
Automatic merge of jdk:master into master
2 parents d71614e + fd206e1 commit d024f85

File tree

3 files changed

+76
-41
lines changed

3 files changed

+76
-41
lines changed
 

‎src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/posix/elf/ELFFileParser.java

+72-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2004, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -116,13 +116,13 @@ class ELFHeaderImpl implements ELFHeader {
116116
private int version; // Elf32_Word
117117
/** Virtual address to which the system first transfers control.
118118
* If there is no entry point for the file the value is 0. */
119-
private int entry_point; // Elf32_Addr
119+
private long entry_point; // Elf32_Addr
120120
/** Program header table offset in bytes. If there is no program
121121
* header table the value is 0. */
122-
private int ph_offset; // Elf32_Off
122+
private long ph_offset; // Elf32_Off
123123
/** Section header table offset in bytes. If there is no section
124124
* header table the value is 0. */
125-
private int sh_offset; // Elf32_Off
125+
private long sh_offset; // Elf32_Off
126126
/** Processor specific flags. */
127127
private int flags; // Elf32_Word
128128
/** ELF header size in bytes. */
@@ -165,9 +165,9 @@ class ELFHeaderImpl implements ELFHeader {
165165
file_type = readShort();
166166
arch = readShort();
167167
version = readInt();
168-
entry_point = readInt();
169-
ph_offset = readInt();
170-
sh_offset = readInt();
168+
entry_point = readWord();
169+
ph_offset = readWord();
170+
sh_offset = readWord();
171171
flags = readInt();
172172
eh_size = readShort();
173173
ph_entry_size = readShort();
@@ -384,23 +384,23 @@ class ELFSectionHeaderImpl implements ELFSectionHeader {
384384
/** Section content and semantics. */
385385
private int type; // Elf32_Word
386386
/** Flags. */
387-
private int flags; // Elf32_Word
387+
private long flags; // Elf32_Word
388388
/** If the section will be in the memory image of a process this
389389
* will be the address at which the first byte of section will be
390390
* loaded. Otherwise, this value is 0. */
391-
private int address; // Elf32_Addr
391+
private long address; // Elf32_Addr
392392
/** Offset from beginning of file to first byte of the section. */
393-
private int section_offset; // Elf32_Off
393+
private long section_offset; // Elf32_Off
394394
/** Size in bytes of the section. TYPE_NOBITS is a special case. */
395-
private int size; // Elf32_Word
395+
private long size; // Elf32_Word
396396
/** Section header table index link. */
397397
private int link; // Elf32_Word
398398
/** Extra information determined by the section type. */
399399
private int info; // Elf32_Word
400400
/** Address alignment constraints for the section. */
401-
private int address_alignment; // Elf32_Word
401+
private long address_alignment; // Elf32_Word
402402
/** Size of a fixed-size entry, 0 if none. */
403-
private int entry_size; // Elf32_Word
403+
private long entry_size; // Elf32_Word
404404

405405
/** Memoized symbol table. */
406406
private MemoizedObject[] symbols;
@@ -416,14 +416,14 @@ class ELFSectionHeaderImpl implements ELFSectionHeader {
416416
seek(offset);
417417
name_ndx = readInt();
418418
type = readInt();
419-
flags = readInt();
420-
address = readInt();
421-
section_offset = readInt();
422-
size = readInt();
419+
flags = readWord();
420+
address = readWord();
421+
section_offset = readWord();
422+
size = readWord();
423423
link = readInt();
424424
info = readInt();
425-
address_alignment = readInt();
426-
entry_size = readInt();
425+
address_alignment = readWord();
426+
entry_size = readWord();
427427

428428
switch (type) {
429429
case ELFSectionHeader.TYPE_NULL:
@@ -433,10 +433,10 @@ class ELFSectionHeaderImpl implements ELFSectionHeader {
433433
case ELFSectionHeader.TYPE_SYMTBL:
434434
case ELFSectionHeader.TYPE_DYNSYM:
435435
// Setup the symbol table.
436-
int num_entries = size / entry_size;
436+
int num_entries = (int)(size / entry_size);
437437
symbols = new MemoizedObject[num_entries];
438438
for (int i = 0; i < num_entries; i++) {
439-
final int symbolOffset = section_offset +
439+
final long symbolOffset = section_offset +
440440
(i * entry_size);
441441
symbols[i] = new MemoizedObject() {
442442
public Object computeValue() {
@@ -447,24 +447,26 @@ public Object computeValue() {
447447
break;
448448
case ELFSectionHeader.TYPE_STRTBL:
449449
// Setup the string table.
450-
final int strTableOffset = section_offset;
451-
final int strTableSize = size;
450+
final long strTableOffset = section_offset;
451+
final long strTableSize = size;
452+
assert32bitLong(strTableSize); // must fit in 32-bits
452453
stringTable = new MemoizedObject() {
453454
public Object computeValue() {
454455
return new ELFStringTableImpl(strTableOffset,
455-
strTableSize);
456+
(int)strTableSize);
456457
}
457458
};
458459
break;
459460
case ELFSectionHeader.TYPE_RELO_EXPLICIT:
460461
break;
461462
case ELFSectionHeader.TYPE_HASH:
462-
final int hashTableOffset = section_offset;
463-
final int hashTableSize = size;
463+
final long hashTableOffset = section_offset;
464+
final long hashTableSize = size;
465+
assert32bitLong(hashTableSize); // must fit in 32-bits
464466
hashTable = new MemoizedObject() {
465467
public Object computeValue() {
466468
return new ELFHashTableImpl(hashTableOffset,
467-
hashTableSize);
469+
(int)hashTableSize);
468470
}
469471
};
470472
break;
@@ -531,7 +533,7 @@ public int getLink() {
531533
return link;
532534
}
533535

534-
public int getOffset() {
536+
public long getOffset() {
535537
return section_offset;
536538
}
537539
}
@@ -625,10 +627,10 @@ class ELFSymbolImpl implements ELFSymbol {
625627
private int name_ndx; // Elf32_Word
626628
/** Value of the associated symbol. This may be an address or
627629
* an absolute value. */
628-
private int value; // Elf32_Addr
630+
private long value; // Elf32_Addr
629631
/** Size of the symbol. 0 if the symbol has no size or the size
630632
* is unknown. */
631-
private int size; // Elf32_Word
633+
private long size; // Elf32_Word
632634
/** Specifies the symbol type and beinding attributes. */
633635
private byte info; // unsigned char
634636
/** Currently holds the value of 0 and has no meaning. */
@@ -646,12 +648,28 @@ class ELFSymbolImpl implements ELFSymbol {
646648
ELFSymbolImpl(long offset, int section_type) throws ELFException {
647649
seek(offset);
648650
this.offset = offset;
649-
name_ndx = readInt();
650-
value = readInt();
651-
size = readInt();
652-
info = readByte();
653-
other = readByte();
654-
section_header_ndx = readShort();
651+
switch (getObjectSize()) {
652+
case CLASS_32: {
653+
name_ndx = readInt();
654+
value = readInt();
655+
size = readInt();
656+
info = readByte();
657+
other = readByte();
658+
section_header_ndx = readShort();
659+
break;
660+
}
661+
case CLASS_64: {
662+
name_ndx = readInt();
663+
info = readByte();
664+
other = readByte();
665+
section_header_ndx = readShort();
666+
value = readWord();
667+
size = readWord();
668+
break;
669+
}
670+
default:
671+
throw new ELFException("Invalid Object Size.");
672+
}
655673

656674
this.section_type = section_type;
657675

@@ -701,7 +719,7 @@ public long getValue() {
701719
return value;
702720
}
703721

704-
public int getSize() {
722+
public long getSize() {
705723
return size;
706724
}
707725
}
@@ -923,6 +941,17 @@ long readLong() throws ELFException {
923941
}
924942
}
925943

944+
long readWord() throws ELFException {
945+
switch (getObjectSize()) {
946+
case CLASS_32:
947+
return readInt();
948+
case CLASS_64:
949+
return readLong();
950+
default:
951+
throw new ELFException("Invalid Object Size.");
952+
}
953+
}
954+
926955
/** Signed byte utility functions used for converting from big-endian
927956
* (MSB) to little-endian (LSB). */
928957
short byteSwap(short arg) {
@@ -1030,6 +1059,12 @@ long unsignedByteSwap(int arg) {
10301059
return (long)(((long)unsignedByteSwap((short)arg)) << 16) |
10311060
((long)unsignedByteSwap((short)(arg >>> 16)));
10321061
}
1062+
1063+
void assert32bitLong(long x) {
1064+
if (x != (long)(int)x) {
1065+
throw new ELFException("64-bit value does not fit in 32-bits: " + x);
1066+
}
1067+
}
10331068
}
10341069

10351070
public static void main(String args[]) {

‎src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/posix/elf/ELFSectionHeader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -117,5 +117,5 @@ public interface ELFSectionHeader {
117117
/** Returns the name of the section or null if the section has no name. */
118118
public String getName();
119119
/** Returns the offset in bytes to the beginning of the section. */
120-
public int getOffset();
120+
public long getOffset();
121121
}

‎src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/posix/elf/ELFSymbol.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -73,5 +73,5 @@ public interface ELFSymbol {
7373

7474
/** Size of the symbol. 0 if the symbol has no size or the size
7575
* is unknown. */
76-
public int getSize();
76+
public long getSize();
7777
}

0 commit comments

Comments
 (0)
Please sign in to comment.