- switch ( sect->type() ) {
- case ld::Section::typeZeroFill:
- case ld::Section::typeTentativeDefs:
- sect->atoms.erase(std::remove_if(sect->atoms.begin(), sect->atoms.end(), InSet(moveToData)), sect->atoms.end());
- break;
- case ld::Section::typeUnclassified:
- if ( (strcmp(sect->sectionName(), "__data") == 0) && (strcmp(sect->segmentName(), "__DATA") == 0) )
- sect->atoms.insert(sect->atoms.end(), moveToData.begin(), moveToData.end());
- break;
- default:
- break;
+ if ( sect->type() == ld::Section::typeUnclassified ) {
+ if ( (strcmp(sect->sectionName(), "__data") == 0) && (strcmp(sect->segmentName(), "__DATA") == 0) )
+ dataSect = sect;
+ }
+ }
+
+ if ( dataSect != NULL ) {
+ // add atoms to __data
+ dataSect->atoms.insert(dataSect->atoms.end(), moveToData.begin(), moveToData.end());
+ // remove atoms from original sections
+ for (std::vector<ld::Internal::FinalSection*>::iterator sit=_state.sections.begin(); sit != _state.sections.end(); ++sit) {
+ ld::Internal::FinalSection* sect = *sit;
+ switch ( sect->type() ) {
+ case ld::Section::typeZeroFill:
+ case ld::Section::typeTentativeDefs:
+ sect->atoms.erase(std::remove_if(sect->atoms.begin(), sect->atoms.end(), InSet(moveToData)), sect->atoms.end());
+ break;
+ default:
+ break;
+ }
+ }
+ // update atom-to-section map
+ for (std::set<const ld::Atom*>::iterator it=moveToData.begin(); it != moveToData.end(); ++it) {
+ _state.atomToSection[*it] = dataSect;