+ ld::Internal::FinalSection* fs = NULL;
+ const char* sectName = atom.section().sectionName();
+ 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() )
+ sectName = FinalSection::_s_DATA_zerofill.sectionName();
+ else
+ sectName = FinalSection::_s_DATA_common.sectionName();
+ }
+ // Support for -move_to_r._segment
+ if ( atom.symbolTableInclusion() == ld::Atom::symbolTableIn ) {
+ const char* dstSeg;
+ //fprintf(stderr, "%s\n", atom.name());
+ bool wildCardMatch;
+ if ( _options.moveRwSymbol(atom.name(), 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 {
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -move_to_rw_segment mapped it to %s/%s\n", atom.name(), dstSeg, sectName);
+ fs = this->getFinalSection(dstSeg, sectName, sectType);
+ }
+ }
+ if ( (fs == NULL) && _options.moveRoSymbol(atom.name(), 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 {
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -move_to_ro_segment mapped it to %s/%s\n", atom.name(), dstSeg, sectName);
+ fs = this->getFinalSection(dstSeg, sectName, ld::Section::typeCode);
+ }
+ }
+ }
+ // support for -rename_section and -rename_segment
+ if ( fs == NULL ) {
+ const std::vector<Options::SectionRename>& sectRenames = _options.sectionRenames();
+ const std::vector<Options::SegmentRename>& segRenames = _options.segmentRenames();
+ for ( std::vector<Options::SectionRename>::const_iterator it=sectRenames.begin(); it != sectRenames.end(); ++it) {
+ if ( (strcmp(sectName, it->fromSection) == 0) && (strcmp(atom.section().segmentName(), it->fromSegment) == 0) ) {
+ if ( _options.useDataConstSegment() && (strcmp(sectName, "__const") == 0)
+ && (strcmp(atom.section().segmentName(), "__DATA") == 0) && hasReferenceToWeakExternal(atom) ) {
+ // if __DATA,__const atom has pointer to weak external symbol, don't move to __DATA_CONST
+ fs = this->getFinalSection("__DATA", "__const_weak", 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
+ fs = this->getFinalSection("__DATA", "__got_weak", sectType);
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', contains pointers to weak symbols, so mapped it to __DATA/__got_weak\n", atom.name());
+ }
+ else {
+ fs = this->getFinalSection(it->toSegment, it->toSection, sectType);
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -rename_section mapped it to %s/%s\n", atom.name(), fs->segmentName(), fs->sectionName());
+ }
+ }
+ }
+ if ( fs == NULL ) {
+ for ( std::vector<Options::SegmentRename>::const_iterator it=segRenames.begin(); it != segRenames.end(); ++it) {
+ if ( strcmp(atom.section().segmentName(), it->fromSegment) == 0 ) {
+ if ( _options.traceSymbolLayout() )
+ printf("symbol '%s', -rename_segment mapped it to %s/%s\n", atom.name(), it->toSegment, sectName);
+ fs = this->getFinalSection(it->toSegment, sectName, 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());
+ }
+