@@ -1979,7 +1979,7 @@ void InitOffsetsSection::setUp() {
1979
1979
ObjCMethListSection::ObjCMethListSection ()
1980
1980
: SyntheticSection(segment_names::text, section_names::objcMethList) {
1981
1981
flags = S_ATTR_NO_DEAD_STRIP;
1982
- align = m_align ;
1982
+ align = relativeOffsetSize ;
1983
1983
}
1984
1984
1985
1985
// Go through all input method lists and ensure that we have selrefs for all
@@ -1993,7 +1993,7 @@ void ObjCMethListSection::setUp() {
1993
1993
uint32_t structSize = structSizeAndFlags & m_structSizeMask;
1994
1994
1995
1995
// Method name is immediately after header
1996
- uint32_t methodNameOff = m_methodListHeaderSize ;
1996
+ uint32_t methodNameOff = methodListHeaderSize ;
1997
1997
1998
1998
// Loop through all methods, and ensure a selref for each of them exists.
1999
1999
while (methodNameOff < isec->data .size ()) {
@@ -2016,19 +2016,19 @@ void ObjCMethListSection::setUp() {
2016
2016
// Calculate section size and final offsets for where InputSection's need to be
2017
2017
// written.
2018
2018
void ObjCMethListSection::finalize () {
2019
- // m_size will be the total size of the __objc_methlist section
2020
- m_size = 0 ;
2019
+ // sectionSize will be the total size of the __objc_methlist section
2020
+ sectionSize = 0 ;
2021
2021
for (ConcatInputSection *isec : inputs) {
2022
- // We can also use m_size as write offset for isec
2023
- assert (m_size == alignToPowerOf2 (m_size, m_align ) &&
2022
+ // We can also use sectionSize as write offset for isec
2023
+ assert (sectionSize == alignToPowerOf2 (sectionSize, relativeOffsetSize ) &&
2024
2024
" expected __objc_methlist to be aligned by default with the "
2025
2025
" required section alignment" );
2026
- isec->outSecOff = m_size ;
2026
+ isec->outSecOff = sectionSize ;
2027
2027
2028
2028
isec->isFinal = true ;
2029
2029
uint32_t relativeListSize =
2030
- methodListSizeToRelativeMethodListSize (isec->data .size ());
2031
- m_size += relativeListSize;
2030
+ computeRelativeMethodListSize (isec->data .size ());
2031
+ sectionSize += relativeListSize;
2032
2032
2033
2033
// If encoding the method list in relative offset format shrinks the size,
2034
2034
// then we also need to adjust symbol sizes to match the new size. Note that
@@ -2061,7 +2061,7 @@ void ObjCMethListSection::writeTo(uint8_t *bufStart) const {
2061
2061
uint32_t writtenSize = writeRelativeMethodList (isec, buf);
2062
2062
buf += writtenSize;
2063
2063
}
2064
- assert (buf - bufStart == m_size &&
2064
+ assert (buf - bufStart == sectionSize &&
2065
2065
" Written size does not match expected section size" );
2066
2066
}
2067
2067
@@ -2122,8 +2122,10 @@ void ObjCMethListSection::writeRelativeOffsetForIsec(
2122
2122
uint32_t delta = symVA - currentVA;
2123
2123
write32le (buf + outSecOff, delta);
2124
2124
2125
+ // Move one pointer forward in the absolute method list
2125
2126
inSecOff += target->wordSize ;
2126
- outSecOff += sizeof (uint32_t );
2127
+ // Move one relative offset forward in the relative method list (32 bits)
2128
+ outSecOff += relativeOffsetSize;
2127
2129
}
2128
2130
2129
2131
// Write a relative method list to buf, return the size of the written
@@ -2135,16 +2137,16 @@ ObjCMethListSection::writeRelativeMethodList(const ConcatInputSection *isec,
2135
2137
// value flag
2136
2138
uint32_t structSizeAndFlags = 0 , structCount = 0 ;
2137
2139
readMethodListHeader (isec->data .data (), structSizeAndFlags, structCount);
2138
- structSizeAndFlags |= m_relMethodHeaderFlag ;
2140
+ structSizeAndFlags |= relMethodHeaderFlag ;
2139
2141
writeMethodListHeader (buf, structSizeAndFlags, structCount);
2140
2142
2141
- assert (m_methodListHeaderSize +
2142
- (structCount * m_pointersPerStruct * target->wordSize ) ==
2143
+ assert (methodListHeaderSize +
2144
+ (structCount * pointersPerStruct * target->wordSize ) ==
2143
2145
isec->data .size () &&
2144
2146
" Invalid computed ObjC method list size" );
2145
2147
2146
- uint32_t inSecOff = m_methodListHeaderSize ;
2147
- uint32_t outSecOff = m_methodListHeaderSize ;
2148
+ uint32_t inSecOff = methodListHeaderSize ;
2149
+ uint32_t outSecOff = methodListHeaderSize ;
2148
2150
2149
2151
// Go through the method list and encode input absolute pointers as relative
2150
2152
// offsets. writeRelativeOffsetForIsec will be incrementing inSecOff and
@@ -2162,27 +2164,26 @@ ObjCMethListSection::writeRelativeMethodList(const ConcatInputSection *isec,
2162
2164
assert (inSecOff == isec->data .size () &&
2163
2165
" Invalid actual ObjC method list size" );
2164
2166
assert (
2165
- outSecOff == methodListSizeToRelativeMethodListSize (inSecOff) &&
2167
+ outSecOff == computeRelativeMethodListSize (inSecOff) &&
2166
2168
" Mismatch between input & output size when writing relative method list" );
2167
2169
return outSecOff;
2168
2170
}
2169
2171
2170
2172
// Given the size of an ObjC method list InputSection, return the size of the
2171
2173
// method list when encoded in relative offsets format. We can do this without
2172
- // decoding the actual data, as it can be directly infered from the size of the
2174
+ // decoding the actual data, as it can be directly inferred from the size of the
2173
2175
// isec.
2174
- uint32_t
2175
- ObjCMethListSection::methodListSizeToRelativeMethodListSize ( uint32_t iSecSize) {
2176
- uint32_t oldPointersSize = iSecSize - m_methodListHeaderSize ;
2176
+ uint32_t ObjCMethListSection::computeRelativeMethodListSize (
2177
+ uint32_t absoluteMethodListSize) const {
2178
+ uint32_t oldPointersSize = absoluteMethodListSize - methodListHeaderSize ;
2177
2179
uint32_t pointerCount = oldPointersSize / target->wordSize ;
2178
- assert (((pointerCount % m_pointersPerStruct ) == 0 ) &&
2180
+ assert (((pointerCount % pointersPerStruct ) == 0 ) &&
2179
2181
" __objc_methlist expects method lists to have multiple-of-3 pointers" );
2180
2182
2181
- constexpr uint32_t sizeOfRelativeOffset = sizeof (uint32_t );
2182
- uint32_t newPointersSize = pointerCount * sizeOfRelativeOffset;
2183
- uint32_t newTotalSize = m_methodListHeaderSize + newPointersSize;
2183
+ uint32_t newPointersSize = pointerCount * relativeOffsetSize;
2184
+ uint32_t newTotalSize = methodListHeaderSize + newPointersSize;
2184
2185
2185
- assert ((newTotalSize <= iSecSize ) &&
2186
+ assert ((newTotalSize <= absoluteMethodListSize ) &&
2186
2187
" Expected relative method list size to be smaller or equal than "
2187
2188
" original size" );
2188
2189
return newTotalSize;
@@ -2191,15 +2192,15 @@ ObjCMethListSection::methodListSizeToRelativeMethodListSize(uint32_t iSecSize) {
2191
2192
// Read a method list header from buf
2192
2193
void ObjCMethListSection::readMethodListHeader (const uint8_t *buf,
2193
2194
uint32_t &structSizeAndFlags,
2194
- uint32_t &structCount) {
2195
+ uint32_t &structCount) const {
2195
2196
structSizeAndFlags = read32le (buf);
2196
2197
structCount = read32le (buf + sizeof (uint32_t ));
2197
2198
}
2198
2199
2199
2200
// Write a method list header to buf
2200
2201
void ObjCMethListSection::writeMethodListHeader (uint8_t *buf,
2201
2202
uint32_t structSizeAndFlags,
2202
- uint32_t structCount) {
2203
+ uint32_t structCount) const {
2203
2204
write32le (buf, structSizeAndFlags);
2204
2205
write32le (buf + sizeof (structSizeAndFlags), structCount);
2205
2206
}
0 commit comments