From 253a3ccc498926408aefa712fdbb167c73b2b04c Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 21 Jan 2017 00:11:55 -0500 Subject: [PATCH] delay adding a symbol for the section name. --- link.cpp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/link.cpp b/link.cpp index 19f55a3..ff3ef98 100644 --- a/link.cpp +++ b/link.cpp @@ -474,7 +474,10 @@ void one_module(const std::vector &data, // duplicate label error... } + +/* // add entry for name? or handle via undefined symbol lookup below? + handled at end if symbol undeinfed. sym.name = s.name; sym.section = virtual_section; @@ -488,7 +491,7 @@ void one_module(const std::vector &data, } else { // duplicate label error... } - +*/ sym.name = "_END_" + s.name; upper_case(sym.name); @@ -856,13 +859,34 @@ void generate_end() { */ for (const auto &s : sections) { - if (!s.end_symbol) continue; - symbol &sym = symbols[s.end_symbol]; - sym.section = s.number; - sym.type = S_REL; - sym.flags = SF_DEF | SF_GBL; - sym.offset = s.size; + // if there is an undefined symbol matching the section name, add it. + if ((s.flags & SEC_NONAME) == 0) { + + auto iter = symbol_map.find(s.name); + if (iter != symbol_map.end()) { + + symbol &sym = symbols[iter->second]; + if (sym.type == S_UND) { + undefined_symbols.erase(s.name); + sym.section = s.number; + sym.type = S_REL; + sym.flags = SF_DEF | SF_GBL; + sym.offset = 0; + } + } + } + + + if (s.end_symbol) { + + symbol &sym = symbols[s.end_symbol]; + + sym.section = s.number; + sym.type = S_REL; + sym.flags = SF_DEF | SF_GBL; + sym.offset = s.size; + } }