); + + if ( _hasSourceVersionLoadCommand ) + sz += sizeof(macho_source_version_command
); if ( _hasThreadLoadCommand ) sz += this->threadLoadCommandSize(); + + if ( _hasEntryPointLoadCommand ) + sz += sizeof(macho_entry_point_command
); if ( _hasEncryptionLoadCommand ) sz += sizeof(macho_encryption_info_command
);
@@ -377,6 +391,12 @@ uint64_t HeaderAndLoadCommandsAtom::size() const
if ( _hasFunctionStartsLoadCommand )
sz += sizeof(macho_linkedit_data_command );
+ if ( _hasDataInCodeLoadCommand )
+ sz += sizeof(macho_linkedit_data_command );
+
+ if ( _hasDependentDRInfo )
+ sz += sizeof(macho_linkedit_data_command );
+
return sz;
}
@@ -409,8 +429,14 @@ uint32_t HeaderAndLoadCommandsAtom::commandsCount() const
if ( _hasVersionLoadCommand )
++count;
+ if ( _hasSourceVersionLoadCommand )
+ ++count;
+
if ( _hasThreadLoadCommand )
++count;
+
+ if ( _hasEntryPointLoadCommand )
+ ++count;
if ( _hasEncryptionLoadCommand )
++count;
@@ -436,6 +462,12 @@ uint32_t HeaderAndLoadCommandsAtom::commandsCount() const
if ( _hasFunctionStartsLoadCommand )
++count;
+ if ( _hasDataInCodeLoadCommand )
+ ++count;
+
+ if ( _hasDependentDRInfo )
+ ++count;
+
return count;
}
@@ -473,6 +505,8 @@ uint32_t HeaderAndLoadCommandsAtom::flags() const
else {
if ( _options.outputKind() == Options::kStaticExecutable ) {
bits |= MH_NOUNDEFS;
+ if ( _options.positionIndependentExecutable() )
+ bits |= MH_PIE;
}
else if ( _options.outputKind() == Options::kPreload ) {
bits |= MH_NOUNDEFS;
@@ -519,33 +553,15 @@ uint32_t HeaderAndLoadCommandsAtom::flags() const
return bits;
}
-template <> uint32_t HeaderAndLoadCommandsAtom )], _options.installPath());
return p + sz;
@@ -1024,62 +1053,27 @@ uint8_t* HeaderAndLoadCommandsAtom::copyVersionLoadCommand(uint8_t* p) const
cmd->set_cmd(LC_VERSION_MIN_MACOSX);
cmd->set_cmdsize(sizeof(macho_version_min_command ));
cmd->set_version((uint32_t)macVersion);
- cmd->set_reserved(0);
+ cmd->set_sdk(_options.sdkVersion());
}
else {
cmd->set_cmd(LC_VERSION_MIN_IPHONEOS);
cmd->set_cmdsize(sizeof(macho_version_min_command ));
cmd->set_version((uint32_t)iOSVersion);
- cmd->set_reserved(0);
+ cmd->set_sdk(_options.sdkVersion());
}
return p + sizeof(macho_version_min_command );
}
-
-template <>
-uint32_t HeaderAndLoadCommandsAtom * cmd = (macho_source_version_command *)p;
+ cmd->set_cmd(LC_SOURCE_VERSION);
+ cmd->set_cmdsize(sizeof(macho_source_version_command ));
+ cmd->set_version(_options.sourceVersion());
+ return p + sizeof(macho_source_version_command );
}
-template <>
-uint8_t* HeaderAndLoadCommandsAtom * cmd = (macho_entry_point_command *)p;
+ cmd->set_cmd(LC_MAIN);
+ cmd->set_cmdsize(sizeof(macho_entry_point_command ));
+ assert(_state.entryPoint != NULL);
+ pint_t start = _state.entryPoint->finalAddress();
+ if ( _state.entryPoint->isThumb() )
+ start |= 1ULL;
+ cmd->set_entryoff(start - this->finalAddress());
+ cmd->set_stacksize(_options.hasCustomStack() ? _options.customStackSize() : 0 );
+ return p + sizeof(macho_entry_point_command );
+}
+
+
template * cmd = (macho_linkedit_data_command *)p;
+ cmd->set_cmd(LC_DATA_IN_CODE);
+ cmd->set_cmdsize(sizeof(macho_linkedit_data_command ));
+ cmd->set_dataoff(_writer.dataInCodeSection->fileOffset);
+ cmd->set_datasize(_writer.dataInCodeSection->size);
+ return p + sizeof(macho_linkedit_data_command );
+}
+
+
+template * cmd = (macho_linkedit_data_command *)p;
+ cmd->set_cmd(LC_DYLIB_CODE_SIGN_DRS);
+ cmd->set_cmdsize(sizeof(macho_linkedit_data_command ));
+ cmd->set_dataoff(_writer.dependentDRsSection->fileOffset);
+ cmd->set_datasize(_writer.dependentDRsSection->size);
+ return p + sizeof(macho_linkedit_data_command );
+}
+
+
template