[PATCH] D47414: [llvm-objcopy] Fix null symbol handling

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 08:00:24 PDT 2018


jhenderson added a comment.

Let's imagine the case where we add an option `--print-symbol-value=<index>` which prints the value of the symbol at the specified index. I think it's clear that we should not prevent a user from printing the symbol at index 0 (i.e. the null symbol) - yes the value is always 0, but that doesn't stop us from printing it. It is clearly not the `SymbolTableSection`'s responsibility to get the value from the symbol - it should be the symbol's responsibility to provide such an interface, and the caller should use it directly. As such, we would need a way to retrieve the symbol at index 0 from the symbol table. If a developer is trying to implement this, it makes sense for them to call `getSymbolByIndex`, but then they see that there is an error check for index 0. How do they then retrieve the null symbol? They can't, so they'll have to put some special case handling in for index 0. In other words, I disagree with you that a user will never want to read the null symbol. Manipulating it is perhaps another matter, but I don't care too much about verifying that it hasn't been adjusted - perhaps there's a good platform-specific reason somebody wants to?

A couple of related questions I'd like to be clear on:

1. What do you think should be the return value of SymbolTable.size() when there is only the null symbol around?
2. What do you think should be the return value of SymbolTable.empty() when there is only the null symbol around?


Repository:
  rL LLVM

https://reviews.llvm.org/D47414





More information about the llvm-commits mailing list