@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, this); // our content (but not our size) depends on the offset and size // of the corresponding element LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); LayoutDecision elOffset = decisions.get(el).getDecision(LayoutDecision.Kind.OFFSET); LayoutDecision elSize = decisions.get(el).getDecision(LayoutDecision.Kind.SIZE); deps.add(BuildDependency.createOrGet(ourContent, elOffset)); deps.add(BuildDependency.createOrGet(ourContent, elSize)); return deps; }
public static BuildDependency createOrGet(LayoutDecision depending, LayoutDecision dependedOn) { try { return new BuildDependency(depending, dependedOn); } catch (DuplicateDependencyException ex) { return ex.existing; } }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, this); // our content depends on the offset and size of strtab, and offset of symtab LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); LayoutDecision strtabSize = decisions.get(symtab.strtab).getDecision(LayoutDecision.Kind.SIZE); LayoutDecision strtabOffset = decisions.get(symtab.strtab).getDecision(LayoutDecision.Kind.OFFSET); LayoutDecision symtabOffset = decisions.get(symtab).getDecision(LayoutDecision.Kind.OFFSET); deps.add(BuildDependency.createOrGet(ourContent, strtabSize)); deps.add(BuildDependency.createOrGet(ourContent, strtabOffset)); deps.add(BuildDependency.createOrGet(ourContent, symtabOffset)); return deps; } }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, this); // our size is fixed; // our content depends on the offset and size of the ExportTrieElement LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(export).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(export).getDecision(LayoutDecision.Kind.SIZE))); return deps; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, this); LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(el).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(el).getDecision(LayoutDecision.Kind.SIZE))); return deps; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { // The Header depends on the section count and symbol table size and offset. // We don't use the default dependencies, because our offset mustn't depend on anything. HashSet<BuildDependency> dependencies = new HashSet<>(); LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); LayoutDecision ourOffset = decisions.get(this).getDecision(LayoutDecision.Kind.OFFSET); LayoutDecision ourSize = decisions.get(this).getDecision(LayoutDecision.Kind.SIZE); LayoutDecision shtSize = decisions.get(sht).getDecision(LayoutDecision.Kind.SIZE); LayoutDecision symtOffset = decisions.get(symtab).getDecision(LayoutDecision.Kind.OFFSET); LayoutDecision symtSize = decisions.get(symtab).getDecision(LayoutDecision.Kind.SIZE); // Mark that our offset depends on our size. dependencies.add(BuildDependency.createOrGet(ourOffset, ourSize)); dependencies.add(BuildDependency.createOrGet(ourContent, shtSize)); dependencies.add(BuildDependency.createOrGet(ourContent, symtOffset)); dependencies.add(BuildDependency.createOrGet(ourContent, symtSize)); return dependencies; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, this); // our content (but not our size) depends on the offsets and sizes of every text section LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); for (Section s : getSections()) { MachOSection ms = (MachOSection) s; if (ms.flags.contains(SectionFlag.SOME_INSTRUCTIONS)) { deps.add(BuildDependency.createOrGet(ourContent, decisions.get(s).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(s).getDecision(LayoutDecision.Kind.SIZE))); } } return deps; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { // our content depends on the section header table size and offset, // and, if present, the program header table size and offset // We don't use the default dependencies, because our offset mustn't depend on anything. // Also, our size MUST NOT depend on our content, because other offsets in the file // (e.g. SHT, PHT) must be decided before content, and we need to give a size so that // that nextAvailableOffset remains defined. // So, our size comes first. HashSet<BuildDependency> dependencies = new HashSet<>(); LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); LayoutDecision ourOffset = decisions.get(this).getDecision(LayoutDecision.Kind.OFFSET); LayoutDecision ourSize = decisions.get(this).getDecision(LayoutDecision.Kind.SIZE); LayoutDecision shtSize = decisions.get(sht).getDecision(LayoutDecision.Kind.SIZE); LayoutDecision shtOffset = decisions.get(sht).getDecision(LayoutDecision.Kind.OFFSET); // Mark that our offset depends on our size. dependencies.add(BuildDependency.createOrGet(ourOffset, ourSize)); dependencies.add(BuildDependency.createOrGet(ourContent, shtSize)); dependencies.add(BuildDependency.createOrGet(ourContent, shtOffset)); return dependencies; }
public static HashSet<BuildDependency> basicDependencies(Map<Element, LayoutDecisionMap> decisions, Element el, boolean sizeOnContent, boolean vaddrOnOffset) { HashSet<BuildDependency> deps = new HashSet<>(); /* * As a minimum, we specify that the offset and vaddr of an element depend on its size. This * is so that once we assign an offset or vaddr, the "next available" offset/vaddr can * always be computed -- using the size which we require to have already been decided. */ deps.add(BuildDependency.createOrGet(decisions.get(el).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(el).getDecision(LayoutDecision.Kind.SIZE))); if (decisions.get(el).getDecision(LayoutDecision.Kind.VADDR) != null) { deps.add(BuildDependency.createOrGet(decisions.get(el).getDecision(LayoutDecision.Kind.VADDR), decisions.get(el).getDecision(LayoutDecision.Kind.SIZE))); } if (sizeOnContent) { deps.add(BuildDependency.createOrGet(decisions.get(el).getDecision(LayoutDecision.Kind.SIZE), decisions.get(el).getDecision(LayoutDecision.Kind.CONTENT))); } // if we have a vaddr, by default it depends on our offset if (vaddrOnOffset && decisions.get(el).getDecision(LayoutDecision.Kind.VADDR) != null) { deps.add(BuildDependency.createOrGet(decisions.get(el).getDecision(LayoutDecision.Kind.VADDR), decisions.get(el).getDecision(LayoutDecision.Kind.OFFSET))); } return deps; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, this); // our content depends on strtab content LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); LayoutDecision strtabContent = decisions.get(strtab).getDecision(LayoutDecision.Kind.CONTENT); deps.add(BuildDependency.createOrGet(ourContent, strtabContent)); /* * We also depend on the vaddr of any referenced defined symbol. It doesn't matter whether * we're dynamic! Every Mach-O section has a vaddr, even in a relocatable file. */ for (Entry e : entries) { Section s = e.getDefinedSection(); if (s != null) { deps.add(BuildDependency.createOrGet(ourContent, decisions.get(s).getDecision(LayoutDecision.Kind.VADDR))); } } return deps; }
@Override public Set<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, getElement()); LayoutDecision ourContent = decisions.get(getElement()).getDecision(LayoutDecision.Kind.CONTENT); LayoutDecision ourVaddr = decisions.get(getElement()).getDecision(LayoutDecision.Kind.VADDR); LayoutDecision rodataVaddr = decisions.get(getRodataSection()).getDecision(LayoutDecision.Kind.VADDR); deps.add(BuildDependency.createOrGet(ourContent, ourVaddr)); deps.add(BuildDependency.createOrGet(ourContent, rodataVaddr)); return deps; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { /* We use minimal deps because our size doesn't depend on our bytewise content. */ HashSet<BuildDependency> deps = ObjectFile.minimalDependencies(decisions, this); /* * Our content depends on the content of our symtab. WHY? it's only the abstract content, * not the physical content. Try removing this one. */ LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); // LayoutDecision symtabContent = // decisions.get(syms).getDecision(LayoutProperty.Kind.CONTENT); // deps.add(BuildDependency.createOrGet(ourContent, symtabContent)); /* If we're dynamic, it also depends on the vaddr of all referenced sections. */ if (isDynamic()) { Set<ELFSection> referenced = new HashSet<>(); for (Entry ent : entries.keySet()) { referenced.add(ent.section); } for (ELFSection es : referenced) { deps.add(BuildDependency.createOrGet(ourContent, decisions.get(es).getDecision(LayoutDecision.Kind.VADDR))); } } return deps; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { ArrayList<BuildDependency> ourDeps = new ArrayList<>(ObjectFile.defaultDependencies(decisions, this)); // we depend on the contents of our strtab ourDeps.add(BuildDependency.createOrGet(decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT), decisions.get(strtab).getDecision(LayoutDecision.Kind.CONTENT))); // if we're dynamic, we also depend on vaddrs of any sections into which our symbols refer if (isDynamic()) { Set<ELFSection> referencedSections = new HashSet<>(); for (Entry ent : entries) { ELFSection es = ent.getReferencedSection(); if (es != null) { referencedSections.add(es); } } for (ELFSection es : referencedSections) { ourDeps.add(BuildDependency.createOrGet(decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT), decisions.get(es).getDecision(LayoutDecision.Kind.VADDR))); } } return ourDeps; }
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { /* * Our contents depend on * * - the content, size and offset of shstrtab (Q. Why content? A. Because we write * string *indices*.) * * - the size and offset of every other element in the file. (Q. Why size? A. Because * the SHT entry includes the size.) * * - the vaddrs of every allocated section */ HashSet<BuildDependency> deps = ObjectFile.defaultDependencies(decisions, this); LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); // to construct a dependency, first we must have constructed the decisions deps.add(BuildDependency.createOrGet(ourContent, decisions.get(shstrtab).getDecision(LayoutDecision.Kind.SIZE))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(shstrtab).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(shstrtab).getDecision(LayoutDecision.Kind.CONTENT))); decisions.get(shstrtab).getDecision(LayoutDecision.Kind.OFFSET); decisions.get(shstrtab).getDecision(LayoutDecision.Kind.CONTENT); for (Element e : getElements()) { if (e != this && e != shstrtab) { deps.add(BuildDependency.createOrGet(ourContent, decisions.get(e).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(e).getDecision(LayoutDecision.Kind.SIZE))); } } return deps; }
deps.add(BuildDependency.createOrGet(ourOffset, hdrOffset)); deps.add(BuildDependency.createOrGet(ourOffset, hdrSize)); deps.add(BuildDependency.createOrGet(nextOffset, prevOffset)); deps.add(BuildDependency.createOrGet(nextOffset, prevSize)); deps.add(BuildDependency.createOrGet(ourContent, nextOffset)); deps.add(BuildDependency.createOrGet(ourContent, nextSize)); prevOffset = nextOffset; prevSize = nextSize; LayoutDecision relocOffset = decisions.get(reloctable).getDecision(LayoutDecision.Kind.OFFSET); LayoutDecision relocSize = decisions.get(reloctable).getDecision(LayoutDecision.Kind.SIZE); deps.add(BuildDependency.createOrGet(relocOffset, prevOffset)); deps.add(BuildDependency.createOrGet(relocOffset, prevSize)); deps.add(BuildDependency.createOrGet(ourContent, relocOffset)); deps.add(BuildDependency.createOrGet(ourContent, relocSize)); deps.add(BuildDependency.createOrGet(symtabOffset, relocOffset)); deps.add(BuildDependency.createOrGet(symtabOffset, relocSize));
deps.add(BuildDependency.createOrGet(ourContent, decisions.get(s).getDecision(LayoutDecision.Kind.SIZE))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(s).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(ourContent, decisions.get(s).getDecision(LayoutDecision.Kind.VADDR))); if (e instanceof MachORelocationElement && ((MachORelocationElement) e).relocatesSegment(this)) { deps.add(BuildDependency.createOrGet(ourContent, decisions.get(e).getDecision(LayoutDecision.Kind.OFFSET)));
@Override public Iterable<BuildDependency> getDependencies(Map<Element, LayoutDecisionMap> decisions) { // our content depends on the offset of every section we're going to reference HashSet<BuildDependency> deps = ObjectFile.defaultDependencies(decisions, this); ArrayList<Section> requiredOffsets = new ArrayList<>(); for (LoadCommand c : loadCommands) { if (c instanceof SymtabCommand) { SymtabCommand syms = (SymtabCommand) c; for (Symbol sym : syms.symtab) { if (sym.isDefined() && sym.isFunction() && !sym.isAbsolute()) { Section s = sym.getDefinedSection(); assert s != null; requiredOffsets.add(s); } } } } LayoutDecision ourContent = decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT); for (Section s : requiredOffsets) { deps.add(BuildDependency.createOrGet(ourContent, decisions.get(s).getDecision(LayoutDecision.Kind.OFFSET))); } return deps; }
deps.add(BuildDependency.createOrGet(decisions.get(e).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(prev).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(decisions.get(s.get(0)).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(prevNonEmptySegment.get(prevNonEmptySegment.size() - 1)).getDecision(LayoutDecision.Kind.OFFSET))); deps.add(BuildDependency.createOrGet(decisions.get(s.get(0)).getDecision(LayoutDecision.Kind.VADDR), decisions.get(prevNonEmptySegment.get(prevNonEmptySegment.size() - 1)).getDecision(LayoutDecision.Kind.VADDR))); deps.add(BuildDependency.createOrGet(decisions.get(this).getDecision(LayoutDecision.Kind.CONTENT), decisions.get(cmd).getDecision(LayoutDecision.Kind.SIZE))); deps.add(BuildDependency.createOrGet(decisions.get(this).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(this).getDecision(LayoutDecision.Kind.SIZE))); for (Element el : seg) { for (LoadCommand cmd : loadCommands) { deps.add(BuildDependency.createOrGet(decisions.get(el).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(cmd).getDecision(LayoutDecision.Kind.OFFSET))); Segment64Command segCmd = (Segment64Command) seg; if (previousSegCmd != null) { deps.add(BuildDependency.createOrGet(decisions.get(segCmd).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(previousSegCmd).getDecision(LayoutDecision.Kind.OFFSET))); if (!(cmd instanceof Segment64Command)) { if (previousCmd != null) { deps.add(BuildDependency.createOrGet(decisions.get(cmd).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(previousCmd).getDecision(LayoutDecision.Kind.OFFSET))); } else { firstNonSegmentCmd = cmd; deps.add(BuildDependency.createOrGet(decisions.get(firstNonSegmentCmd).getDecision(LayoutDecision.Kind.OFFSET), decisions.get(previousSegCmd).getDecision(LayoutDecision.Kind.OFFSET)));
BuildDependency dep = BuildDependency.createOrGet(d, offsetBootstrapDecision); l1.add(dep); l2.add(dep);