Add missing BlobCore::clone() implementation #191

Merged
locriandev merged 1 commit from fix-blobcore-clone-missing-implementation into 1030.6.3-ld64-956.6 2026-04-03 10:12:24 -05:00
locriandev commented 2026-04-03 05:27:00 -05:00 (Migrated from github.com)

Problem

The Blob<BlobType> template class has a clone() method (line 184-185) that calls this->BlobCore::clone(), but the BlobCore::clone() method is not declared in blob.h nor implemented in blob.cpp. This causes a linker error when the method is actually invoked.

Discovery

This issue was discovered when building osxcross with RHEL 9.6 toolchain (GCC 14.2), which performs stricter linking checks than previous versions. The same code compiled successfully with RHEL 9.4 but fails with undefined symbol errors on RHEL 9.6:

undefined reference to BlobCore::clone() const

Solution

This PR adds:

  1. Declaration of BlobCore::clone() in blob.h (after stringAt() methods)
  2. Implementation in blob.cpp that performs a deep copy

The implementation follows the same pattern as other BlobCore methods, using malloc and memcpy to create a proper deep copy of the blob:

BlobCore *BlobCore::clone() const
{
    size_t len = this->length();
    BlobCore *copy = (BlobCore *)malloc(len);
    if (copy) memcpy(copy, this, len);
    return copy;
}

Testing

  • Tested with RHEL 9.6 / GCC 14.2 building osxcross cross-compiler toolchain
  • Successfully links and executes without errors
  • Backwards compatible with older toolchains

Files Changed

  • cctools/ld64/src/ld/code-sign-blobs/blob.h: Added method declaration
  • cctools/ld64/src/ld/code-sign-blobs/blob.cpp: Added implementation

This has been a latent bug that newer compilers/linkers are now catching.

## Problem The `Blob<BlobType>` template class has a `clone()` method (line 184-185) that calls `this->BlobCore::clone()`, but the `BlobCore::clone()` method is **not declared** in `blob.h` nor **implemented** in `blob.cpp`. This causes a linker error when the method is actually invoked. ## Discovery This issue was discovered when building osxcross with **RHEL 9.6 toolchain (GCC 14.2)**, which performs stricter linking checks than previous versions. The same code compiled successfully with RHEL 9.4 but fails with undefined symbol errors on RHEL 9.6: ``` undefined reference to BlobCore::clone() const ``` ## Solution This PR adds: 1. **Declaration** of `BlobCore::clone()` in `blob.h` (after `stringAt()` methods) 2. **Implementation** in `blob.cpp` that performs a deep copy The implementation follows the same pattern as other BlobCore methods, using `malloc` and `memcpy` to create a proper deep copy of the blob: ```cpp BlobCore *BlobCore::clone() const { size_t len = this->length(); BlobCore *copy = (BlobCore *)malloc(len); if (copy) memcpy(copy, this, len); return copy; } ``` ## Testing - Tested with RHEL 9.6 / GCC 14.2 building osxcross cross-compiler toolchain - Successfully links and executes without errors - Backwards compatible with older toolchains ## Files Changed - `cctools/ld64/src/ld/code-sign-blobs/blob.h`: Added method declaration - `cctools/ld64/src/ld/code-sign-blobs/blob.cpp`: Added implementation This has been a latent bug that newer compilers/linkers are now catching.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
miles/cctools-port!191
No description provided.