Skip to content

Commit

Permalink
cctools 1010.6, ld64 951.9
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoechtrager committed Aug 5, 2024
1 parent a98286d commit 65f196e
Show file tree
Hide file tree
Showing 30 changed files with 276 additions and 78 deletions.
35 changes: 33 additions & 2 deletions cctools/include/mach-o/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,12 @@ struct mach_header_64 {
the platforms macOS, macCatalyst,
iOSSimulator, tvOSSimulator and
watchOSSimulator. */


#define MH_IMPLICIT_PAGEZERO 0x10000000 /* main executable has no __PAGEZERO
segment. Instead, loader (xnu)
will load program high and block
out all memory below it. */

#define MH_DYLIB_IN_CACHE 0x80000000 /* Only for use on dylibs. When this bit
is set, the dylib is part of the dyld
shared cache, rather than loose in
Expand Down Expand Up @@ -670,7 +675,7 @@ struct fvmlib_command {
};

/*
* Dynamicly linked shared libraries are identified by two things. The
* Dynamically linked shared libraries are identified by two things. The
* pathname (the name of the library as found for execution), and the
* compatibility version number. The pathname must match and the compatibility
* number in the user of the library must be greater than or equal to the
Expand Down Expand Up @@ -699,6 +704,30 @@ struct dylib_command {
struct dylib dylib; /* the library identification */
};


/*
* An alternate encoding for: LC_LOAD_DYLIB.
* The flags field contains independent flags DYLIB_USE_*
* First supported in macOS 15, iOS 18.
*/
struct dylib_use_command {
uint32_t cmd; /* LC_LOAD_DYLIB or LC_LOAD_WEAK_DYLIB */
uint32_t cmdsize; /* overall size, including path */
uint32_t nameoff; /* == 28, dylibs's path offset */
uint32_t marker; /* == DYLIB_USE_MARKER */
uint32_t current_version; /* dylib's current version number */
uint32_t compat_version; /* dylib's compatibility version number */
uint32_t flags; /* DYLIB_USE_... flags */
};
#define DYLIB_USE_WEAK_LINK 0x01
#define DYLIB_USE_REEXPORT 0x02
#define DYLIB_USE_UPWARD 0x04
#define DYLIB_USE_DELAYED_INIT 0x08

#define DYLIB_USE_MARKER 0x1a741800



/*
* A dynamically linked shared library may be a subframework of an umbrella
* framework. If so it will be linked with "-umbrella umbrella_name" where
Expand Down Expand Up @@ -1287,6 +1316,8 @@ struct build_tool_version {
#define PLATFORM_TVOSSIMULATOR 8
#define PLATFORM_WATCHOSSIMULATOR 9
#define PLATFORM_DRIVERKIT 10
#define PLATFORM_VISIONOS 11
#define PLATFORM_VISIONOSSIMULATOR 12


#define PLATFORM_FIRMWARE 13
Expand Down
2 changes: 1 addition & 1 deletion cctools/include/mach-o/nlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ struct nlist_64 {
/*
* To simplify stripping of objects that use are used with the dynamic link
* editor, the static link editor marks the symbols defined an object that are
* referenced by a dynamicly bound object (dynamic shared libraries, bundles).
* referenced by a dynamically bound object (dynamic shared libraries, bundles).
* With this marking strip knows not to strip these symbols.
*/
#define REFERENCED_DYNAMICALLY 0x0010
Expand Down
5 changes: 5 additions & 0 deletions cctools/include/mach/machine-cctools.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ extern vm_offset_t interrupt_stack[];
#define CPU_TYPE_RS6000 ((cpu_type_t) 17)
#define CPU_TYPE_MC98000 ((cpu_type_t) 18)
#define CPU_TYPE_POWERPC ((cpu_type_t) 18)
#define CPU_TYPE_RISCV32 ((cpu_type_t) 24) /* cctools-port */

#define CPU_ARCH_ABI64 0x1000000
#define CPU_ARCH_ABI64_32 0x2000000
#define CPU_TYPE_POWERPC64 ((cpu_type_t)(CPU_TYPE_POWERPC | CPU_ARCH_ABI64))
Expand Down Expand Up @@ -397,6 +399,9 @@ extern vm_offset_t interrupt_stack[];
#define CPU_SUBTYPE_POWERPC_7450 ((cpu_subtype_t) 11)
#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)

/*
* RISC-V subtypes
*/
/*
* VEO subtypes
* Note: the CPU_SUBTYPE_VEO_ALL will likely change over time to be defined as
Expand Down
14 changes: 12 additions & 2 deletions cctools/include/standalone/getsect.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,22 @@
extern "C" {
#endif /* __cplusplus */

extern uint8_t *getsectiondata(const struct mach_header_64 *mhp,
extern uint8_t *getsectiondata(
#if __LP64__
const struct mach_header_64* mhp,
#else
const struct mach_header* mhp,
#endif
const char *segname,
const char *sectname,
unsigned long *size);

extern uint8_t *getsegmentdata(const struct mach_header_64 *mhp,
extern uint8_t *getsegmentdata(
#if __LP64__
const struct mach_header_64* mhp,
#else
const struct mach_header* mhp,
#endif
const char *segname,
unsigned long *size);

Expand Down
5 changes: 5 additions & 0 deletions cctools/include/stuff/bytesex.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@
#undef VALID_THREAD_STATE_FLAVOR
#include <mach/m88k/thread_status.h>
#include <mach/i860/thread_status.h>
#include <machine/types.h> /* Get basic integer types for thread_status.h which get blocked by defining *MACHTYPES_H_ */
#if defined (__i386__) || defined (__x86_64__)
#include <mach/i386/thread_status.h>
#else
#define __x86_64__
#define _I386_MACHTYPES_H_ /* Suppress duplicate type errors */
#include <mach/i386/thread_status.h>
#undef _I386_MACHTYPES_H_
#undef __x86_64__
#endif
#include <mach/hppa/thread_status.h>
Expand All @@ -60,7 +63,9 @@
#include <mach/arm/thread_status.h>
#else
#define __arm__
#define _ARM_MACHTYPES_H_ /* Suppress duplicate type errors */
#include <mach/arm/thread_status.h>
#undef _ARM_MACHTYPES_H_
#undef __arm__
#endif
#include <mach-o/nlist.h>
Expand Down
2 changes: 2 additions & 0 deletions cctools/ld64/doc/man/man1/ld-classic.1
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ is a hexadecimal number with an optional leading 0x. If
.Ar size
is zero, the linker will not generate a page zero segment. By default on 32-bit architectures the page zero size
is 4KB. On 64-bit architectures, the default size is 4GB.
.It implicit_pagezero
When used on main executables, omits the __PAGEZERO segment, and relies on the loader blocking out low memory.
.It Fl stack_size Ar size
Specifies the maximum stack size for the main thread in a program. Without this option a program has a 8MB stack.
The argument
Expand Down
6 changes: 5 additions & 1 deletion cctools/ld64/src/abstraction/MachOFileAbstraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@
#define N_COLD_FUNC 0x0400
#endif

enum
#ifndef MH_IMPLICIT_PAGEZERO
#define MH_IMPLICIT_PAGEZERO 0x10000000
#endif

enum
{
RISCV_RELOC_UNSIGNED = 0, // for simple pointers
RISCV_RELOC_SUBTRACTOR = 1, // must be followed by a RISCV_RELOC_UNSIGNED
Expand Down
2 changes: 2 additions & 0 deletions cctools/ld64/src/ld/HeaderAndLoadCommands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ uint32_t HeaderAndLoadCommandsAtom<A>::flags() const
bits |= MH_APP_EXTENSION_SAFE;
if (_options.isSimulatorSupportDylib())
bits |= MH_SIM_SUPPORT;
if ( _options.implicitPageZero() )
bits |= MH_IMPLICIT_PAGEZERO;
}
if ( _options.hasExecutableStack() )
bits |= MH_ALLOW_STACK_EXECUTION;
Expand Down
5 changes: 3 additions & 2 deletions cctools/ld64/src/ld/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ void InputFiles::forEachInitialAtom(ld::File::AtomHandler& handler, ld::Internal
// add implicit __dso_handle label
handler.doAtom(DSOHandleAtom::_s_atomExecutable);
handler.doAtom(DSOHandleAtom::_s_atomAll);
if ( _options.pageZeroSize() != 0 )
if ( !_options.implicitPageZero() && (_options.pageZeroSize() != 0) )
handler.doAtom(*new PageZeroAtom(_options.pageZeroSize()));
if ( _options.hasCustomStack() && !_options.needsEntryPointLoadCommand() )
handler.doAtom(*new CustomStackAtom(_options.customStackSize()));
Expand Down Expand Up @@ -1617,7 +1617,8 @@ void InputFiles::dylibs(ld::Internal& state)

bool skipForPlatform = false;
skipForPlatform = _options.platforms().contains(ld::Platform::driverKit) ||
_options.platforms().contains(ld::Platform::sepOS);
_options.platforms().contains(ld::Platform::sepOS) ||
_options.platforms().contains(ld::Platform::freestanding);


// <rdar://problem/10807040> give an error when -nostdlib is used and libSystem is missing
Expand Down
8 changes: 4 additions & 4 deletions cctools/ld64/src/ld/LinkEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2273,15 +2273,15 @@ void CodeSignatureAtom::encode() const
}
libcd_set_exec_seg(_sigRef, 0, textSize, flags);

// update section size now that code signature size is known
codeSignSect->size = libcd_superblob_size(_sigRef);

// allocate space for code-signature (never used, sign is written directly to output buffer in hash())
this->_encodedData.alloc(codeSignSect->size);
this->_encodedData.alloc(libcd_superblob_size(_sigRef));

// align to pointer size
this->_encodedData.pad_to_size(8);
this->_encoded = true;

// update section size now that code signature size + padding is known
codeSignSect->size = this->_encodedData.size();
}

void CodeSignatureAtom::hash(uint8_t* wholeFileBuffer) const
Expand Down
29 changes: 29 additions & 0 deletions cctools/ld64/src/ld/LinkEditClassic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,35 @@ void SectionRelocationsAtom<riscv32>::encodeSectionReloc(ld::Internal::FinalSect
relocs.push_back(reloc1);
break;

case ld::Fixup::kindStoreLittleEndian32:
case ld::Fixup::kindStoreTargetAddressLittleEndian32:
if ( entry.fromTarget != NULL ) {
// this is a pointer-diff
reloc1.set_r_address(address);
reloc1.set_r_symbolnum(symbolNum);
reloc1.set_r_pcrel(false);
reloc1.set_r_length(2);
reloc1.set_r_extern(external);
reloc1.set_r_type(RISCV_RELOC_UNSIGNED);
reloc2.set_r_address(address);
reloc2.set_r_symbolnum(fromSymbolNum);
reloc2.set_r_pcrel(false);
reloc2.set_r_length(2);
reloc2.set_r_extern(fromExternal);
reloc2.set_r_type(RISCV_RELOC_SUBTRACTOR);
relocs.push_back(reloc2);
relocs.push_back(reloc1);
} else {
// regular pointer
reloc1.set_r_address(address);
reloc1.set_r_symbolnum(symbolNum);
reloc1.set_r_pcrel(false);
reloc1.set_r_length(2);
reloc1.set_r_extern(external);
reloc1.set_r_type(RISCV_RELOC_UNSIGNED);
relocs.push_back(reloc1);
}
break;
default:
assert(0 && "need to handle risc-v -r reloc");

Expand Down
Loading

0 comments on commit 65f196e

Please sign in to comment.