From c2fdd58215ef187d228d5bcf2ff969a14cdc0c04 Mon Sep 17 00:00:00 2001 From: Khomutov Nikita Date: Mon, 8 Apr 2024 10:45:04 +0300 Subject: [PATCH 1/5] [ADLT] cleanups Signed-off-by: Khomutov Nikita Change-Id: I3cb8dc7f27d1ca08efc9b93aac60c7f49dfdb84d --- lld/ELF/ADLTSection.h | 6 ++-- lld/ELF/SyntheticSections.cpp | 61 ++++++++++++++--------------------- lld/ELF/SyntheticSections.h | 8 ++++- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/lld/ELF/ADLTSection.h b/lld/ELF/ADLTSection.h index 3441ddb8af29..05a9bda23b70 100644 --- a/lld/ELF/ADLTSection.h +++ b/lld/ELF/ADLTSection.h @@ -89,9 +89,9 @@ typedef struct { adlt_cross_section_array_t initArray; adlt_cross_section_array_t finiArray; adlt_blob_array_t dtNeeded; // array of adlt_dt_needed_index_t[] elems - adlt_cross_section_ref_t sharedLocalSymbolIndex; - adlt_cross_section_ref_t sharedGlobalSymbolIndex; - adlt_blob_u16_array_t phIndexes; // program header index array, typeof(e_phnum) + adlt_cross_section_ref_t sharedLocalSymbolIndex; + adlt_cross_section_ref_t sharedGlobalSymbolIndex; + adlt_blob_u16_array_t phIndexes; // program header index array, typeof(e_phnum) } adlt_psod_t; typedef struct { diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 2e2204392008..e44d94d3d6dd 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -4176,21 +4176,10 @@ adlt_psod_t AdltSection::serialize(const SoData& soData) const { 0x0, // .fini_array function addresses are located at the start soData.finiArraySec->size, // size } : adlt_cross_section_array_t{0, 0, 0}, - adlt_blob_array_t { // .dtNeeded - 0x0, // offset, filled array write in blob - soData.dtNeededs.size() * sizeof(adlt_dt_needed_index_t) - }, - adlt_cross_section_ref_t { // .sharedLocalSymbolIndex - 0, // .secIndex // TODO: dynsym? - soData.sharedLocalIndex, // .offset - }, - adlt_cross_section_ref_t { // .sharedGlobalSymbolIndex - 0, // .secIndex // TODO: dynsym? - soData.sharedGlobalIndex, // .offset - }, - adlt_blob_u16_array_t { // .phIndexes - 0x0, 0 - } + adlt_blob_array_t {0x0, 0} // .dtNeeded, filled in writeTo + adlt_cross_section_ref_t {0,0}, // .sharedLocalSymbolIndex TODO + adlt_cross_section_ref_t {0, 0}, // .sharedGlobalSymbolIndex TOOD + adlt_blob_u16_array_t {0x0, 0}, // .phIndexes, filled in writeTo }; } @@ -4212,9 +4201,21 @@ size_t AdltSection::estimateBlobSize() const { } template -size_t AdltSection::writeDtNeededVec( - uint8_t* buff, const DtNeededsVec& neededVec) const { - if (neededVec.empty()) return 0; +template +adlt_blob_array_t AdltSection::writeArray( + uint8_t* buff, size_t offset, const SmallVector& data) { + if (data.empty()) return {0x0, 0}; + + const size_t to_write = data.size_in_bytes(); + memcpy(buff + offset, data.data(), to_write); + + return {offset, to_write}; +} + +template +adlt_blob_array_t AdltSection::writeDtNeeded( + uint8_t* buff, size_t offset, const DtNeededsVec& neededVec) { + if (neededVec.empty()) return {0x0, 0}; SmallVector needIndexes; needIndexes.reserve(neededVec.size()); @@ -4226,8 +4227,7 @@ size_t AdltSection::writeDtNeededVec( }); } - memcpy(buff, needIndexes.data(), needIndexes.size_in_bytes()); - return needIndexes.size_in_bytes(); + return writeArray(buff, offset, needIndexes); } template @@ -4249,28 +4249,15 @@ void AdltSection::writeTo(uint8_t* buf) { memcpy(blob_buf + blob_off, &adltBlobStartMark, sizeof(adltBlobStartMark)); blob_off += sizeof(adltBlobStartMark); - // dt-needed for(const auto& it : llvm::enumerate(soInputs)) { const SoData& soData = it.value(); adlt_psod_t& psod = psods[it.index()]; - const size_t written = writeDtNeededVec(blob_buf + blob_off, soData.dtNeededs); - psod.dtNeeded.offset = blob_off; - psod.dtNeeded.size = written; - blob_off += written; - } - - // phIndexes - for (const auto& it : llvm::enumerate(soInputs)) { - const SoData& soData = it.value(); - adlt_psod_t& psod = psods[it.index()]; + psod.dtNeeded = writeDtNeeded(blob_buf, blob_off, soData.dtNeededs); + blob_off += psod.dtNeeded.size; - const size_t written = soData.phIndexes.size_in_bytes();; - memcpy(blob_buf + blob_off, - soData.phIndexes.data(), soData.phIndexes.size_in_bytes()); - psod.phIndexes.offset = blob_off; - psod.phIndexes.size = written; - blob_off += written; + psod.phIndexes = writeArray(blob_buf, blob_off, soData.phIndexes); + blob_off += psod.phIndexes.size; } // finalize header.blobSize diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 8292495940fa..4e1e748b4d40 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -1280,7 +1280,13 @@ private: adlt_psod_t serialize(const SoData&) const; size_t estimateBlobSize() const; - size_t writeDtNeededVec(uint8_t* buff, const DtNeededsVec& neededVec) const; + + template + adlt_blob_array_t writeArray(uint8_t* buff, size_t offset, + const SmallVector& data); + + adlt_blob_array_t writeDtNeeded(uint8_t* buff, size_t offset, + const DtNeededsVec& neededVec); private: StringTableSection& strTabSec; -- Gitee From 61c43ab6539c805151c6e24a195cd52a1fd30aaf Mon Sep 17 00:00:00 2001 From: Khomutov Nikita Date: Mon, 8 Apr 2024 12:16:04 +0300 Subject: [PATCH 2/5] [ADLT] add relaDyn segments to .adlt section Signed-off-by: Khomutov Nikita Change-Id: I93a97ba72d98c876ab890ce687385f9410aeef4c Signed-off-by: Khomutov Nikita --- lld/ELF/ADLTSection.h | 18 ++++++--- lld/ELF/SyntheticSections.cpp | 76 ++++++++++++++++++++++++++--------- lld/ELF/SyntheticSections.h | 19 +++++++-- 3 files changed, 85 insertions(+), 28 deletions(-) diff --git a/lld/ELF/ADLTSection.h b/lld/ELF/ADLTSection.h index 05a9bda23b70..1eb9d6042ef9 100644 --- a/lld/ELF/ADLTSection.h +++ b/lld/ELF/ADLTSection.h @@ -66,12 +66,18 @@ typedef struct { } adlt_semver_t; // DT_NEEDED string index with embedded PSOD index if available -typedef struct { +typedef struct { Elf64_Off hasInternalPSOD : 1; // true if soname Elf64_Off PSODindex : 16; // PSOD in the current ADLT image Elf64_Off sonameOffset : 47; // string start in bound .adlt.strtab } adlt_dt_needed_index_t; +typedef struct { + Elf64_Word relType; // relocation type + Elf64_Off startOffet; // segment start offset in .rela.dyn + Elf64_Xword count; // segment length +} adlt_relocations_segment_t; + typedef enum { ADLT_HASH_TYPE_NONE = 0, ADLT_HASH_TYPE_GNU_HASH = 1, @@ -85,13 +91,14 @@ typedef uint8_t adlt_hash_type_t; // Serializable representation per-shared-object-data in .adlt section typedef struct { Elf64_Off soName; // offset in .adlt.strtab - Elf64_Xword soNameHash; // algorithm according to header.stringHashType value + Elf64_Xword soNameHash; // algorithm according to hdr.stringHashType value adlt_cross_section_array_t initArray; adlt_cross_section_array_t finiArray; adlt_blob_array_t dtNeeded; // array of adlt_dt_needed_index_t[] elems - adlt_cross_section_ref_t sharedLocalSymbolIndex; - adlt_cross_section_ref_t sharedGlobalSymbolIndex; - adlt_blob_u16_array_t phIndexes; // program header index array, typeof(e_phnum) + adlt_cross_section_ref_t sharedLocalSymbolIndex; + adlt_cross_section_ref_t sharedGlobalSymbolIndex; + adlt_blob_u16_array_t phIndexes; // program header indexes, typeof(e_phnum) + adlt_blob_array_t relaDynSegs; // adlt_relocations_segment_t[] of the lib } adlt_psod_t; typedef struct { @@ -103,6 +110,7 @@ typedef struct { Elf64_Off blobStart; // offset of binary blob start relative to .adlt Elf64_Xword blobSize; Elf64_Xword overallMappedSize; // bytes, required to map the whole ADLT image + adlt_blob_array_t cmnRelaDynSegs; // adlt_relocations_segment_t[] of image } adlt_section_header_t; static const char adltBlobStartMark[4] = { 0xA, 0xD, 0x1, 0x7 }; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index e44d94d3d6dd..71f9dff744b1 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -4011,20 +4011,30 @@ static_assert( "adlt_dt_needed_index_t have to be an offset with intrused flags" ); +static_assert( + sizeof(adlt_relocations_segment_t) == 24, + "adlt_relocations_segment_t size is 24 bytes" +); + static_assert( sizeof(adlt_hash_type_t) == sizeof(Elf64_Byte), "String hash type enum should occupy only one byte" ); +static_assert( + sizeof(adlt_blob_array_t) == 16, + "blob array reference occupies 16 bytes in PSOD" +); + static_assert(sizeof(adltBlobStartMark) == 4, "0xad17 consist of 4 bytes" ); -static_assert(sizeof(adlt_section_header_t) == 40, - "please udpate version if header has been changed" +static_assert(sizeof(adlt_section_header_t) == 56, + "please update version if header has been changed" ); -static_assert(sizeof(adlt_psod_t) == 128, +static_assert(sizeof(adlt_psod_t) == 144, "please udpate version if adlt_psod_t layout or content changed" ); @@ -4050,6 +4060,8 @@ void AdltSection::finalizeContents() { "the number of input libs exeeds ELF limit on number of sections"); const Elf64_Half soNum = soInputs.size(); + common = makeCommonData(); + header = adlt_section_header_t{ adltSchemaVersion, // .schemaVersion sizeof(adlt_section_header_t), // .schemaHeaderSize @@ -4059,6 +4071,7 @@ void AdltSection::finalizeContents() { getBlobStartOffset(), // .blobStart estimateBlobSize(), // .blobSize 0, // .overallMappedSize + {0, 0}, // .cmnRelaDynSegs, filled in writeTo }; // TODO: estimate and fill overallMappedSize @@ -4119,6 +4132,16 @@ void AdltSection::extractInitFiniArray() { } } +template +typename AdltSection::CommonData +AdltSection::makeCommonData() { + // TODO: fill relaDynSegs + + return CommonData { + {} // relaDynSegs + }; +} + template typename AdltSection::SoData AdltSection::makeSoData(const SharedFileExtended* soext) { @@ -4139,6 +4162,7 @@ AdltSection::makeSoData(const SharedFileExtended* soext) { // TODO: fill data.sharedLocalIndex // TODO: fill data.sharedGlobalIndex + // TODO: fill data.relaDynSegs std::copy(soext->programHeaderIndexes.begin(), soext->programHeaderIndexes.end(), @@ -4176,10 +4200,11 @@ adlt_psod_t AdltSection::serialize(const SoData& soData) const { 0x0, // .fini_array function addresses are located at the start soData.finiArraySec->size, // size } : adlt_cross_section_array_t{0, 0, 0}, - adlt_blob_array_t {0x0, 0} // .dtNeeded, filled in writeTo - adlt_cross_section_ref_t {0,0}, // .sharedLocalSymbolIndex TODO + adlt_blob_array_t {0x0, 0}, // .dtNeeded, filled in writeTo + adlt_cross_section_ref_t {0, 0}, // .sharedLocalSymbolIndex TODO adlt_cross_section_ref_t {0, 0}, // .sharedGlobalSymbolIndex TOOD adlt_blob_u16_array_t {0x0, 0}, // .phIndexes, filled in writeTo + adlt_blob_array_t {0x0, 0}, // .relaDynSegs, filled in writeTo }; } @@ -4195,15 +4220,18 @@ size_t AdltSection::estimateBlobSize() const { for (const auto& soData: soInputs) { blobSize += sizeof(adlt_dt_needed_index_t) * soData.dtNeededs.size(); blobSize += sizeof(uint16_t) * soData.phIndexes.size(); + blobSize += sizeof(adlt_relocations_segment_t) * soData.relaDynSegs.size(); }; + blobSize += sizeof(adlt_relocations_segment_t) * common.relaDynSegs.size(); + return blobSize; } template -template +template adlt_blob_array_t AdltSection::writeArray( - uint8_t* buff, size_t offset, const SmallVector& data) { + uint8_t* buff, size_t offset, const SmallVector& data) { if (data.empty()) return {0x0, 0}; const size_t to_write = data.size_in_bytes(); @@ -4244,26 +4272,36 @@ void AdltSection::writeTo(uint8_t* buf) { // serialize blob data { - uint8_t* const blob_buf = buf + header.blobStart; - size_t blob_off = 0; - memcpy(blob_buf + blob_off, &adltBlobStartMark, sizeof(adltBlobStartMark)); - blob_off += sizeof(adltBlobStartMark); + uint8_t* const blobBuf = buf + header.blobStart; + size_t blobOff = 0; + memcpy(blobBuf + blobOff, &adltBlobStartMark, sizeof(adltBlobStartMark)); + blobOff += sizeof(adltBlobStartMark); + // psod-related data for(const auto& it : llvm::enumerate(soInputs)) { - const SoData& soData = it.value(); - adlt_psod_t& psod = psods[it.index()]; + const auto& soData = it.value(); + auto& psod = psods[it.index()]; + + psod.dtNeeded = writeDtNeeded(blobBuf, blobOff, soData.dtNeededs); + blobOff += psod.dtNeeded.size; - psod.dtNeeded = writeDtNeeded(blob_buf, blob_off, soData.dtNeededs); - blob_off += psod.dtNeeded.size; + psod.phIndexes = writeArray(blobBuf, blobOff, soData.phIndexes); + blobOff += psod.phIndexes.size; + + psod.relaDynSegs = writeArray(blobBuf, blobOff, soData.relaDynSegs); + blobOff += psod.relaDynSegs.size; + } - psod.phIndexes = writeArray(blob_buf, blob_off, soData.phIndexes); - blob_off += psod.phIndexes.size; + // common data + { + header.cmnRelaDynSegs = writeArray(blobBuf, blobOff, common.relaDynSegs); + blobOff += header.cmnRelaDynSegs.size; } // finalize header.blobSize - assert((blob_off <= header.blobSize) && + assert((blobOff <= header.blobSize) && ".adlt-section: blob output exeeds its initial estimation"); - header.blobSize = blob_off; + header.blobSize = blobOff; } // header diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 4e1e748b4d40..3c16cea7451b 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -1257,6 +1257,12 @@ public: Elf64_Off sharedGlobalIndex; // TODO SmallVector phIndexes; // TODO + SmallVector relaDynSegs; // TODO + }; + + // will be used to form some header data + struct CommonData { + SmallVector relaDynSegs; // TODO }; public: @@ -1275,15 +1281,17 @@ private: void linkInternalDtNeeded(); void extractInitFiniArray(); - Elf64_Xword calculateHash(StringRef str) const; + CommonData makeCommonData(); SoData makeSoData(const SharedFileExtended*); + + Elf64_Xword calculateHash(StringRef str) const; adlt_psod_t serialize(const SoData&) const; size_t estimateBlobSize() const; - template + template adlt_blob_array_t writeArray(uint8_t* buff, size_t offset, - const SmallVector& data); + const SmallVector& data); adlt_blob_array_t writeDtNeeded(uint8_t* buff, size_t offset, const DtNeededsVec& neededVec); @@ -1292,7 +1300,10 @@ private: StringTableSection& strTabSec; adlt_section_header_t header = {}; - SmallVector soInputs; + + CommonData common = {}; + SmallVector soInputs; + llvm::DenseMap sonameToIndexMap; }; -- Gitee From 67f49f6635df208fae61da6f9764b252a2c59dd5 Mon Sep 17 00:00:00 2001 From: Khomutov Nikita Date: Tue, 9 Apr 2024 14:43:47 +0300 Subject: [PATCH 3/5] [ADLT] .adlt section: - better size fit for relocation segment - new placeholder: segments for .rela.plt Signed-off-by: Khomutov Nikita Change-Id: Ie160f1593bf4174a7f03d518245d28eb67705665 Signed-off-by: Khomutov Nikita --- lld/ELF/ADLTSection.h | 10 ++++++---- lld/ELF/SyntheticSections.cpp | 37 +++++++++++++++++++++++------------ lld/ELF/SyntheticSections.h | 2 ++ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/lld/ELF/ADLTSection.h b/lld/ELF/ADLTSection.h index 1eb9d6042ef9..5dd3d98ab357 100644 --- a/lld/ELF/ADLTSection.h +++ b/lld/ELF/ADLTSection.h @@ -74,8 +74,8 @@ typedef struct { typedef struct { Elf64_Word relType; // relocation type - Elf64_Off startOffet; // segment start offset in .rela.dyn - Elf64_Xword count; // segment length + Elf64_Word count; // segment length + Elf64_Off startOffset; // segment start offset in .rela.dyn } adlt_relocations_segment_t; typedef enum { @@ -97,8 +97,9 @@ typedef struct { adlt_blob_array_t dtNeeded; // array of adlt_dt_needed_index_t[] elems adlt_cross_section_ref_t sharedLocalSymbolIndex; adlt_cross_section_ref_t sharedGlobalSymbolIndex; - adlt_blob_u16_array_t phIndexes; // program header indexes, typeof(e_phnum) - adlt_blob_array_t relaDynSegs; // adlt_relocations_segment_t[] of the lib + adlt_blob_u16_array_t phIndexes; // program header indexes, typeof(e_phnum) + adlt_blob_array_t relaDynSegs; // adlt_relocations_segment_t[] of the lib + adlt_blob_array_t relaPltSegs; // adlt_relocations_segment_t[] of the lib } adlt_psod_t; typedef struct { @@ -111,6 +112,7 @@ typedef struct { Elf64_Xword blobSize; Elf64_Xword overallMappedSize; // bytes, required to map the whole ADLT image adlt_blob_array_t cmnRelaDynSegs; // adlt_relocations_segment_t[] of image + adlt_blob_array_t cmnRelaPltSegs; // adlt_relocations_segment_t[] of image } adlt_section_header_t; static const char adltBlobStartMark[4] = { 0xA, 0xD, 0x1, 0x7 }; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 71f9dff744b1..b7e110a0cb77 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -4012,8 +4012,8 @@ static_assert( ); static_assert( - sizeof(adlt_relocations_segment_t) == 24, - "adlt_relocations_segment_t size is 24 bytes" + sizeof(adlt_relocations_segment_t) == 16, + "adlt_relocations_segment_t size is 16 bytes" ); static_assert( @@ -4030,11 +4030,11 @@ static_assert(sizeof(adltBlobStartMark) == 4, "0xad17 consist of 4 bytes" ); -static_assert(sizeof(adlt_section_header_t) == 56, +static_assert(sizeof(adlt_section_header_t) == 72, "please update version if header has been changed" ); -static_assert(sizeof(adlt_psod_t) == 144, +static_assert(sizeof(adlt_psod_t) == 160, "please udpate version if adlt_psod_t layout or content changed" ); @@ -4072,6 +4072,7 @@ void AdltSection::finalizeContents() { estimateBlobSize(), // .blobSize 0, // .overallMappedSize {0, 0}, // .cmnRelaDynSegs, filled in writeTo + {0, 0}, // .cmnRelaPltSegs, filled in writeTo }; // TODO: estimate and fill overallMappedSize @@ -4136,9 +4137,11 @@ template typename AdltSection::CommonData AdltSection::makeCommonData() { // TODO: fill relaDynSegs + // TODO: fill relaPltSegs return CommonData { - {} // relaDynSegs + {}, // .relaDynSegs + {}, // .relaPltSegs }; } @@ -4163,6 +4166,7 @@ AdltSection::makeSoData(const SharedFileExtended* soext) { // TODO: fill data.sharedLocalIndex // TODO: fill data.sharedGlobalIndex // TODO: fill data.relaDynSegs + // TODO: fill data.relaPltSegs std::copy(soext->programHeaderIndexes.begin(), soext->programHeaderIndexes.end(), @@ -4194,17 +4198,18 @@ adlt_psod_t AdltSection::serialize(const SoData& soData) const { soData.initArraySec->sectionIndex, 0x0, // .init_array function addresses are located at the start soData.initArraySec->size, // size - } : adlt_cross_section_array_t{0, 0, 0}, + } : adlt_cross_section_array_t{}, soData.finiArraySec ? adlt_cross_section_array_t{ // .finiArray soData.finiArraySec->sectionIndex, 0x0, // .fini_array function addresses are located at the start soData.finiArraySec->size, // size - } : adlt_cross_section_array_t{0, 0, 0}, - adlt_blob_array_t {0x0, 0}, // .dtNeeded, filled in writeTo - adlt_cross_section_ref_t {0, 0}, // .sharedLocalSymbolIndex TODO - adlt_cross_section_ref_t {0, 0}, // .sharedGlobalSymbolIndex TOOD - adlt_blob_u16_array_t {0x0, 0}, // .phIndexes, filled in writeTo - adlt_blob_array_t {0x0, 0}, // .relaDynSegs, filled in writeTo + } : adlt_cross_section_array_t{}, + adlt_blob_array_t {}, // .dtNeeded, filled in writeTo + adlt_cross_section_ref_t {}, // .sharedLocalSymbolIndex TODO + adlt_cross_section_ref_t {}, // .sharedGlobalSymbolIndex TOOD + adlt_blob_u16_array_t {}, // .phIndexes, filled in writeTo + adlt_blob_array_t {}, // .relaDynSegs, filled in writeTo + adlt_blob_array_t {}, // .relaPltSegs, filled in writeTo }; } @@ -4221,9 +4226,11 @@ size_t AdltSection::estimateBlobSize() const { blobSize += sizeof(adlt_dt_needed_index_t) * soData.dtNeededs.size(); blobSize += sizeof(uint16_t) * soData.phIndexes.size(); blobSize += sizeof(adlt_relocations_segment_t) * soData.relaDynSegs.size(); + blobSize += sizeof(adlt_relocations_segment_t) * soData.relaPltSegs.size(); }; blobSize += sizeof(adlt_relocations_segment_t) * common.relaDynSegs.size(); + blobSize += sizeof(adlt_relocations_segment_t) * common.relaPltSegs.size(); return blobSize; } @@ -4290,12 +4297,18 @@ void AdltSection::writeTo(uint8_t* buf) { psod.relaDynSegs = writeArray(blobBuf, blobOff, soData.relaDynSegs); blobOff += psod.relaDynSegs.size; + + psod.relaPltSegs = writeArray(blobBuf, blobOff, soData.relaPltSegs); + blobOff += psod.relaPltSegs.size; } // common data { header.cmnRelaDynSegs = writeArray(blobBuf, blobOff, common.relaDynSegs); blobOff += header.cmnRelaDynSegs.size; + + header.cmnRelaPltSegs = writeArray(blobBuf, blobOff, common.relaPltSegs); + blobOff += header.cmnRelaPltSegs.size; } // finalize header.blobSize diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 3c16cea7451b..c69b95704406 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -1258,11 +1258,13 @@ public: SmallVector phIndexes; // TODO SmallVector relaDynSegs; // TODO + SmallVector relaPltSegs; // TODO }; // will be used to form some header data struct CommonData { SmallVector relaDynSegs; // TODO + SmallVector relaPltSegs; // TODO }; public: -- Gitee From ed963f7f674d4adcafb04d11659e076e5641fa61 Mon Sep 17 00:00:00 2001 From: Khomutov Nikita Date: Wed, 10 Apr 2024 12:14:19 +0300 Subject: [PATCH 4/5] review fix: better naming for common data Signed-off-by: Khomutov Nikita Change-Id: Icf4fdcbbffeda12466a0a735d0814da49a72a01b --- lld/ELF/ADLTSection.h | 8 ++++---- lld/ELF/SyntheticSections.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lld/ELF/ADLTSection.h b/lld/ELF/ADLTSection.h index 5dd3d98ab357..74943e6210c7 100644 --- a/lld/ELF/ADLTSection.h +++ b/lld/ELF/ADLTSection.h @@ -98,8 +98,8 @@ typedef struct { adlt_cross_section_ref_t sharedLocalSymbolIndex; adlt_cross_section_ref_t sharedGlobalSymbolIndex; adlt_blob_u16_array_t phIndexes; // program header indexes, typeof(e_phnum) - adlt_blob_array_t relaDynSegs; // adlt_relocations_segment_t[] of the lib - adlt_blob_array_t relaPltSegs; // adlt_relocations_segment_t[] of the lib + adlt_blob_array_t relaDynSegs; // lib's adlt_relocations_segment_t[] + adlt_blob_array_t relaPltSegs; // lib's adlt_relocations_segment_t[] } adlt_psod_t; typedef struct { @@ -111,8 +111,8 @@ typedef struct { Elf64_Off blobStart; // offset of binary blob start relative to .adlt Elf64_Xword blobSize; Elf64_Xword overallMappedSize; // bytes, required to map the whole ADLT image - adlt_blob_array_t cmnRelaDynSegs; // adlt_relocations_segment_t[] of image - adlt_blob_array_t cmnRelaPltSegs; // adlt_relocations_segment_t[] of image + adlt_blob_array_t relaDynSegs; // common adlt_relocations_segment_t[] + adlt_blob_array_t relaPltSegs; // common adlt_relocations_segment_t[] } adlt_section_header_t; static const char adltBlobStartMark[4] = { 0xA, 0xD, 0x1, 0x7 }; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index b7e110a0cb77..33ae89538d56 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -4071,8 +4071,8 @@ void AdltSection::finalizeContents() { getBlobStartOffset(), // .blobStart estimateBlobSize(), // .blobSize 0, // .overallMappedSize - {0, 0}, // .cmnRelaDynSegs, filled in writeTo - {0, 0}, // .cmnRelaPltSegs, filled in writeTo + {0, 0}, // .relaDynSegs, filled in writeTo + {0, 0}, // .relaPltSegs, filled in writeTo }; // TODO: estimate and fill overallMappedSize @@ -4304,11 +4304,11 @@ void AdltSection::writeTo(uint8_t* buf) { // common data { - header.cmnRelaDynSegs = writeArray(blobBuf, blobOff, common.relaDynSegs); - blobOff += header.cmnRelaDynSegs.size; + header.relaDynSegs = writeArray(blobBuf, blobOff, common.relaDynSegs); + blobOff += header.relaDynSegs.size; - header.cmnRelaPltSegs = writeArray(blobBuf, blobOff, common.relaPltSegs); - blobOff += header.cmnRelaPltSegs.size; + header.relaPltSegs = writeArray(blobBuf, blobOff, common.relaPltSegs); + blobOff += header.relaPltSegs.size; } // finalize header.blobSize -- Gitee From 197fcd773a6bd34b49786670a8b085977c723602 Mon Sep 17 00:00:00 2001 From: Khomutov Nikita Date: Wed, 10 Apr 2024 13:07:11 +0300 Subject: [PATCH 5/5] review fix: add ifdef for elf.h include Signed-off-by: Khomutov Nikita Change-Id: Ib161455d942d6c3c4b48f335b25e8efa1062f358 --- lld/ELF/ADLTSection.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lld/ELF/ADLTSection.h b/lld/ELF/ADLTSection.h index 74943e6210c7..1327de5950ec 100644 --- a/lld/ELF/ADLTSection.h +++ b/lld/ELF/ADLTSection.h @@ -29,6 +29,7 @@ namespace adlt { #include #endif // __cplusplus +#ifndef _ELF_H // part of #include typedef uint16_t Elf64_Half; typedef uint64_t Elf64_Off; @@ -36,6 +37,7 @@ typedef uint64_t Elf64_Addr; typedef uint32_t Elf64_Word; typedef uint64_t Elf64_Xword; typedef uint8_t Elf64_Byte; +#endif // _ELF_H typedef struct { Elf64_Word secIndex; -- Gitee