private static boolean checkEmbeddedOffset(ProgbitsSectionImpl sectionImpl, final int offset, final RelocatableBuffer.Info info) { final ByteBuffer dataBuf = ByteBuffer.wrap(sectionImpl.getContent()).order(sectionImpl.getElement().getOwner().getByteOrder()); if (info.getRelocationSize() == Long.BYTES) { long value = dataBuf.getLong(offset); assert value == 0 || value == 0xDEADDEADDEADDEADL : "unexpected embedded offset"; } else if (info.getRelocationSize() == Integer.BYTES) { int value = dataBuf.getInt(offset); assert value == 0 || value == 0xDEADDEAD : "unexpected embedded offset"; } else { shouldNotReachHere("unsupported relocation size: " + info.getRelocationSize()); } return true; }
private void markRelocationSitesFromMaps(RelocatableBuffer relocationMap, ProgbitsSectionImpl sectionImpl, Map<Object, NativeImageHeap.ObjectInfo> objectMap) { // Create relocation records from a map. // TODO: Should this be a visitor to the map entries, // TODO: so I don't have to expose the entrySet() method? for (Map.Entry<Integer, RelocatableBuffer.Info> entry : relocationMap.entrySet()) { final int offset = entry.getKey(); final RelocatableBuffer.Info info = entry.getValue(); assert checkEmbeddedOffset(sectionImpl, offset, info); // Figure out what kind of relocation site it is. if (info.getTargetObject() instanceof CFunctionPointer) { // References to functions are via relocations to the symbol for the function. markFunctionRelocationSite(sectionImpl, offset, info); } else { // A data relocation. if (sectionImpl.getElement() == textSection) { // A wrinkle on relocations *from* the text section: they are *always* to // constants (in the "constant partition" of the roDataSection). markDataRelocationSiteFromText(relocationMap, sectionImpl, offset, info, objectMap); } else { // Relocations from other sections go to the section containing the target. // Pass along the information about the target. final Object targetObject = info.getTargetObject(); final NativeImageHeap.ObjectInfo targetObjectInfo = objectMap.get(targetObject); markDataRelocationSite(sectionImpl, offset, info, targetObjectInfo); } } } }