[PATCH] D46200: Mitigate relocation overflow [part 2 of 2]
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 17 10:45:46 PDT 2018
ruiu added inline comments.
================
Comment at: ELF/Writer.cpp:1704-1708
+ // These symbols resolve to the image base or ".text" if the section
+ // does not exist. Set symbol value to ".text" mitigates the
+ // possibilities that an relocation from .text section to these
+ // symbols overflows. A special value -1 indicates end of the
+ // section.
----------------
I'd think that this comment could be improved by making it clear what is the default behavior, what your problem is, and how to solve it. The important thing is that future readers will be able to understand this comment without too much context. I'd write something like this.
--
If a section does not exist, there's ambiguity as to how we define _start and _end symbols for an init/fini section. Since the loader assume that the symbols are always defined, we need to always define them. But what value? The loader iterates over all pointers between _start and _end to run global ctors/dtors, so if the section is empty, their symbol values don't actually matter as long as _start and _end point to the same location.
That said, we don't want to set the symbols to 0 (which is probably the simplest value) because that could cause some program to fail to link due to relocation overflow, if their program text is above 2 GiB. We use the address of the .text section instead to prevent that failure.
================
Comment at: ELF/Writer.cpp:1709
+ // section.
+ OutputSection *DefaultOutSec = findSection(".text");
+ if (!DefaultOutSec)
----------------
Since this function is very small, we probably should use shorter names. I'd name this just `Text`.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D46200
More information about the llvm-commits
mailing list