This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Reject symbols pointing to section end
ClosedPublic

Authored by jobnoorman on Mar 16 2023, 4:15 AM.

Details

Summary

Sometimes, symbols are present that point to the end of a section (i.e.,
one-past the highest valid address). Currently, BOLT either rejects
those symbols when they don't point to another existing section, or errs
when they do and the other section is not executable. I suppose BOLT
would accept the symbol when it points to an executable section.

In any case, these symbols should not be considered while discovering
functions and should not result in an error. This patch implements that.

Note that this patch checks explicitly for symbols whose value equals
the end of their section. It might make more sense to verify that the
symbol's value is within [section start, section end). However, I'm not
sure if this could every happen *and* its value does not equal the end.

Another way to implement this is to verify that the BinarySection we
find at the symbol's address actually corresponds to the symbol's
section. I'm not sure what the best approach is so feedback is welcome.

Diff Detail

Event Timeline

jobnoorman created this revision.Mar 16 2023, 4:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2023, 4:15 AM
jobnoorman requested review of this revision.Mar 16 2023, 4:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2023, 4:15 AM

Makes sense, but where did you see this in practice?

LGTM, but small nit - I would swap this new condition with the " if (!Section->isText()) " condition above, since this one is more "univesal" and might appear not inly in text section. And although currently it does not really matter it probably better from the logical standpoint.

Swap check with the if (!Section->isText()) check as suggested by @yota9.

Makes sense, but where did you see this in practice?

This happens when using the RISC-V GNU toolchain in debug mode and emitting relocations:

$ cat test.c
int main() {}

$ riscv64-linux-gnu-gcc -g -Wl,--no-relax,--emit-relocs -o test test.c
$ readelf -s test | grep etext
    73: 000000000000064a     0 NOTYPE  LOCAL  DEFAULT   12 .Letext0

LGTM, but small nit - I would swap this new condition with the " if (!Section->isText()) " condition above, since this one is more "univesal" and might appear not inly in text section. And although currently it does not really matter it probably better from the logical standpoint.

Makes sense, done!

yota9 accepted this revision.Mar 18 2023, 4:46 AM

LGTM, but let's wait next week plz, maybe @rafauler have some other thoughts :)

This revision is now accepted and ready to land.Mar 18 2023, 4:46 AM
rafauler accepted this revision.Mar 20 2023, 6:03 PM

I don't have anything else to add, I think it makes sense.

Thanks for reviewing @yota9, @rafauler! Please note the I don't have commit access so I cannot land this myself.

My author details are Job Noorman <jnoorman@igalia.com>

This revision was automatically updated to reflect the committed changes.
akhuang added inline comments.
bolt/test/X86/section-end-sym.s
8

This flag doesn't work if LLVM is built without asserts enabled -- test probably needs a # REQUIRES: asserts ?

akhuang added inline comments.Mar 22 2023, 5:25 PM
bolt/test/X86/section-end-sym.s
8
jobnoorman added inline comments.Mar 23 2023, 1:32 AM
bolt/test/X86/section-end-sym.s
8

TIL :) Thanks for fixing this!