Comment by malkia
5 years ago
Wait this code can't work - as you holding only a string_view in the Symbol...
// __start_ and __stop_ symbols
for (OutputChunk *chunk : chunks) {
if (is_c_identifier(chunk->name)) {
start(Symbol::intern("__start_" + std::string(chunk->name)), chunk);
stop(Symbol::intern("__stop_" + std::string(chunk->name)), chunk);
}
}
Ah, that's a bug. Thank you for finding it!
This does seem broken, since the temporary string that is created by the concatenation is short lived, and the std::string_view inside the Symbol won't hold on to it, just the pointer to the data.
Or this:
for (std::string_view arg : config.version_script) parse_version_script(std::string(arg));
Although if somehow nothing gets really freed, and std::string() is kept intact after calling the destructor (e.g. it's data() is still valid) then it'll work :)
`parse_version_script` is defined as taking an `std::string`, std::string() over an `std::string_view` will create a new std::string with a copy of the data from arg.