[PATCH] [ELF] Initial support for symbols visibility
Davide Italiano
davide at freebsd.org
Fri Mar 13 11:35:32 PDT 2015
Hi ruiu, shankar.easwaran, rafael,
This can't be committed until I modify llvm-objdump -t to print visibility properly for ELF symbols, but the lld bits should be all there, so this is ready for review.
I'll add an unit test once I'll figure out the llvm-objdump bits properly.
P.S. This also makes _GLOBAL_OFFSET_TABLE hidden by default. Probably should be committed separately.
REPOSITORY
rL LLVM
http://reviews.llvm.org/D8325
Files:
include/lld/Core/DefinedAtom.h
lib/ReaderWriter/ELF/Atoms.h
lib/ReaderWriter/ELF/SectionChunks.h
Index: include/lld/Core/DefinedAtom.h
===================================================================
--- include/lld/Core/DefinedAtom.h
+++ include/lld/Core/DefinedAtom.h
@@ -197,6 +197,14 @@
codeARMThumb, // ARM Thumb instruction set
};
+ // Visibility of the Atom
+ enum Visibility {
+ visibilityDefault,
+ visibilityInternal,
+ visibilityHidden,
+ visibilityProtected,
+ };
+
struct Alignment {
Alignment(int p2, int m = 0)
: powerOf2(p2)
@@ -287,6 +295,9 @@
/// content.
virtual ArrayRef<uint8_t> rawContent() const = 0;
+ /// \brief returns visibility of an Atom.
+ virtual Visibility visibility() const { return visibilityDefault; }
+
/// This class abstracts iterating over the sequence of References
/// in an Atom. Concrete instances of DefinedAtom must implement
/// the derefIterator() and incrementIterator() methods.
Index: lib/ReaderWriter/ELF/Atoms.h
===================================================================
--- lib/ReaderWriter/ELF/Atoms.h
+++ lib/ReaderWriter/ELF/Atoms.h
@@ -807,6 +807,8 @@
ContentType contentType() const override { return typeGOT; }
+ Visibility visibility() const override { return visibilityHidden; }
+
uint64_t size() const override { return 0; }
ContentPermissions permissions() const override { return permRW_; }
Index: lib/ReaderWriter/ELF/SectionChunks.h
===================================================================
--- lib/ReaderWriter/ELF/SectionChunks.h
+++ lib/ReaderWriter/ELF/SectionChunks.h
@@ -729,7 +729,7 @@
template <class ELFT>
void SymbolTable<ELFT>::addDefinedAtom(Elf_Sym &sym, const DefinedAtom *da,
int64_t addr) {
- unsigned char binding = 0, type = 0;
+ unsigned char binding = 0, type = 0, visibility = 0;
sym.st_size = da->size();
DefinedAtom::ContentType ct;
switch (ct = da->contentType()) {
@@ -773,6 +773,21 @@
else
binding = llvm::ELF::STB_GLOBAL;
+ switch (DefinedAtom::Visibility vt = da->visibility()) {
+ case DefinedAtom::visibilityDefault:
+ visibility = llvm::ELF::STV_DEFAULT;
+ break;
+ case DefinedAtom::visibilityInternal:
+ visibility = llvm::ELF::STV_INTERNAL;
+ break;
+ case DefinedAtom::visibilityHidden:
+ visibility = llvm::ELF::STV_HIDDEN;
+ break;
+ case DefinedAtom::visibilityProtected:
+ visibility = llvm::ELF::STV_PROTECTED;
+ break;
+ }
+ sym.setVisibility(visibility);
sym.setBindingAndType(binding, type);
}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8325.21942.patch
Type: text/x-patch
Size: 2533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150313/77258788/attachment.bin>
More information about the llvm-commits
mailing list