+ //fprintf(stderr, "addAtom: %s\n", atom.name());
+ ld::Internal::FinalSection* fs = NULL;
+ const char* curSectName = atom.section().sectionName();
+ const char* curSegName = atom.section().segmentName();
+ ld::Section::Type sectType = atom.section().type();
+ const ld::File* f = atom.file();
+ const char* path = (f != NULL) ? f->path() : NULL;
+ if ( atom.section().type() == ld::Section::typeTentativeDefs ) {
+ // tentative defintions don't have a real section name yet
+ sectType = ld::Section::typeZeroFill;
+ if ( _options.mergeZeroFill() )
+ curSectName = FinalSection::_s_DATA_zerofill.sectionName();
+ else
+ curSectName = FinalSection::_s_DATA_common.sectionName();
+ }
+ // Support for -move_to_r._segment
+ if ( atom.symbolTableInclusion() == ld::Atom::symbolTableIn ) {
+ const char* dstSeg;
+ bool wildCardMatch;
+ if ( inMoveRWChain(atom, path, dstSeg, wildCardMatch) ) {
+ if ( (sectType != ld::Section::typeZeroFill)
+ && (sectType != ld::Section::typeUnclassified)
+ && (sectType != ld::Section::typeTentativeDefs)
+ && (sectType != ld::Section::typeDyldInfo) ) {
+ if ( !wildCardMatch )
+ warning("cannot move symbol '%s' from file %s to segment '%s' because symbol is not data (is %d)", atom.name(), path, dstSeg, sectType);
+ }
+ else {
+ curSegName = dstSeg;
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -move_to_rw_segment mapped it to %s/%s\n", atom.name(), curSegName, curSectName);
+ fs = this->getFinalSection(curSegName, curSectName, sectType);
+ }
+ }
+ if ( (fs == NULL) && inMoveROChain(atom, path, dstSeg, wildCardMatch) ) {
+ if ( (sectType != ld::Section::typeCode)
+ && (sectType != ld::Section::typeUnclassified) ) {
+ if ( !wildCardMatch )
+ warning("cannot move symbol '%s' from file %s to segment '%s' because symbol is not code (is %d)", atom.name(), path, dstSeg, sectType);
+ }
+ else {
+ curSegName = dstSeg;
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -move_to_ro_segment mapped it to %s/%s\n", atom.name(), curSegName, curSectName);
+ fs = this->getFinalSection(curSegName, curSectName, ld::Section::typeCode);
+ }
+ }
+ }
+ // support for -rename_section and -rename_segment
+ for (const Options::SectionRename& rename : _options.sectionRenames()) {
+ if ( (strcmp(curSectName, rename.fromSection) == 0) && (strcmp(curSegName, rename.fromSegment) == 0) ) {
+ if ( _options.useDataConstSegment() && (strcmp(curSectName, "__const") == 0) && (strcmp(curSegName, "__DATA") == 0) && hasReferenceToWeakExternal(atom) ) {
+ // if __DATA,__const atom has pointer to weak external symbol, don't move to __DATA_CONST
+ curSectName = "__const_weak";
+ fs = this->getFinalSection(curSegName, curSectName, sectType);
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', contains pointers to weak symbols, so mapped it to __DATA/__const_weak\n", atom.name());
+ }
+ else if ( _options.useDataConstSegment() && (sectType == ld::Section::typeNonLazyPointer) && hasReferenceToWeakExternal(atom) ) {
+ // if __DATA,__nl_symbol_ptr atom has pointer to weak external symbol, don't move to __DATA_CONST
+ curSectName = "__got_weak";
+ fs = this->getFinalSection("__DATA", curSectName, sectType);
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', contains pointers to weak symbols, so mapped it to __DATA/__got_weak\n", atom.name());
+ }
+ else {
+ curSegName = rename.toSegment;
+ curSectName = rename.toSection;
+ fs = this->getFinalSection(rename.toSegment, rename.toSection, sectType);
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -rename_section mapped it to %s/%s\n", atom.name(), fs->segmentName(), fs->sectionName());
+ }
+ }
+ }
+ for (const Options::SegmentRename& rename : _options.segmentRenames()) {
+ if ( strcmp(curSegName, rename.fromSegment) == 0 ) {
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -rename_segment mapped it to %s/%s\n", atom.name(), rename.toSegment, curSectName);
+ fs = this->getFinalSection(rename.toSegment, curSectName, sectType);
+ }
+ }
+
+ // if no override, use default location
+ if ( fs == NULL ) {
+ fs = this->getFinalSection(atom.section());
+ if ( _options.traceSymbolLayout() && (atom.symbolTableInclusion() == ld::Atom::symbolTableIn) )
+ printf("symbol '%s', use default mapping to %s/%s\n", atom.name(), fs->segmentName(), fs->sectionName());
+ }
+
+ //fprintf(stderr, "InternalState::doAtom(%p), name=%s, sect=%s, finalseg=%s\n", &atom, atom.name(), atom.section().sectionName(), fs->segmentName());