Skip to content

Commit bd233df

Browse files
Merge pull request #63 from DhruvSrivastavaX/1188732_static_global
Global variables are not accessed correctly, as the data/bss sections corrupted.
2 parents 35ac0cb + 2e0029c commit bd233df

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ bool ObjectFileXCOFF::SetLoadAddress(Target &target, lldb::addr_t value,
325325
if (module_sp) {
326326
size_t num_loaded_sections = 0;
327327
SectionList *section_list = GetSectionList();
328+
328329
if (section_list) {
329330
const size_t num_sections = section_list->GetSize();
330331
size_t sect_idx = 0;
@@ -333,16 +334,19 @@ bool ObjectFileXCOFF::SetLoadAddress(Target &target, lldb::addr_t value,
333334
// Iterate through the object file sections to find all of the sections
334335
// that have SHF_ALLOC in their flag bits.
335336
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
336-
if (section_sp && !section_sp->IsThreadSpecific()) {
337-
bool use_offset = false;
338-
if (strcmp(section_sp->GetName().AsCString(), ".text") == 0 ||
339-
strcmp(section_sp->GetName().AsCString(), ".data") == 0 ||
340-
strcmp(section_sp->GetName().AsCString(), ".bss") == 0)
341-
use_offset = true;
342337

338+
if (section_sp && !section_sp->IsThreadSpecific()) {
339+
addr_t load_addr = 0;
340+
if (!value_is_offset)
341+
load_addr = section_sp->GetFileAddress();
342+
else {
343+
if (strcmp(section_sp->GetName().AsCString(), ".text") == 0)
344+
load_addr = section_sp->GetFileOffset() + value;
345+
else /* Other sections: data, bss, loader, dwline, dwinfo, dwabrev */
346+
load_addr = section_sp->GetFileAddress() + value;
347+
}
343348
if (target.GetSectionLoadListPublic().SetSectionLoadAddress(
344-
section_sp, (use_offset ?
345-
(section_sp->GetFileOffset() + value) : (section_sp->GetFileAddress() + value))))
349+
section_sp, load_addr))
346350
++num_loaded_sections;
347351
}
348352
}

0 commit comments

Comments
 (0)