2016-07-09 00:10:27 +08:00
|
|
|
//===- Thunks.h --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_THUNKS_H
|
|
|
|
#define LLD_ELF_THUNKS_H
|
|
|
|
|
|
|
|
#include "Relocations.h"
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace elf {
|
2018-03-30 06:32:13 +08:00
|
|
|
class Defined;
|
2017-11-04 05:21:47 +08:00
|
|
|
class Symbol;
|
2017-03-16 18:40:50 +08:00
|
|
|
class ThunkSection;
|
2016-07-09 00:10:27 +08:00
|
|
|
// Class to describe an instance of a Thunk.
|
|
|
|
// A Thunk is a code-sequence inserted by the linker in between a caller and
|
|
|
|
// the callee. The relocation to the callee is redirected to the Thunk, which
|
|
|
|
// after executing transfers control to the callee. Typical uses of Thunks
|
|
|
|
// include transferring control from non-pi to pi and changing state on
|
|
|
|
// targets like ARM.
|
|
|
|
//
|
2017-11-06 12:35:31 +08:00
|
|
|
// Thunks can be created for Defined, Shared and Undefined Symbols.
|
2017-02-01 18:26:03 +08:00
|
|
|
// Thunks are assigned to synthetic ThunkSections
|
2017-03-16 18:40:50 +08:00
|
|
|
class Thunk {
|
2016-07-09 00:10:27 +08:00
|
|
|
public:
|
2017-11-04 05:21:47 +08:00
|
|
|
Thunk(Symbol &Destination);
|
2016-07-09 00:10:27 +08:00
|
|
|
virtual ~Thunk();
|
|
|
|
|
2018-03-29 05:33:31 +08:00
|
|
|
virtual uint32_t size() = 0;
|
|
|
|
virtual void writeTo(uint8_t *Buf) = 0;
|
2017-02-01 18:26:03 +08:00
|
|
|
|
2018-03-30 06:32:13 +08:00
|
|
|
// All Thunks must define at least one symbol, known as the thunk target
|
|
|
|
// symbol, so that we can redirect relocations to it. The thunk may define
|
|
|
|
// additional symbols, but these are never targets for relocations.
|
2018-03-29 05:33:31 +08:00
|
|
|
virtual void addSymbols(ThunkSection &IS) = 0;
|
2017-02-01 18:26:03 +08:00
|
|
|
|
2018-03-30 06:32:13 +08:00
|
|
|
void setOffset(uint64_t Offset);
|
|
|
|
Defined *addSymbol(StringRef Name, uint8_t Type, uint64_t Value,
|
|
|
|
InputSectionBase &Section);
|
|
|
|
|
2017-02-01 18:26:03 +08:00
|
|
|
// Some Thunks must be placed immediately before their Target as they elide
|
|
|
|
// a branch and fall through to the first Symbol in the Target.
|
2017-02-24 00:49:07 +08:00
|
|
|
virtual InputSection *getTargetInputSection() const { return nullptr; }
|
2016-07-10 06:52:30 +08:00
|
|
|
|
2017-10-12 06:49:24 +08:00
|
|
|
// To reuse a Thunk the caller as identified by the Type must be
|
2017-07-05 17:36:03 +08:00
|
|
|
// compatible with it.
|
2017-10-12 06:49:24 +08:00
|
|
|
virtual bool isCompatibleWith(RelType Type) const { return true; }
|
2017-07-05 17:36:03 +08:00
|
|
|
|
2018-03-30 06:32:13 +08:00
|
|
|
Defined *getThunkTargetSym() const { return Syms[0]; }
|
|
|
|
|
2017-02-01 18:26:03 +08:00
|
|
|
// The alignment requirement for this Thunk, defaults to the size of the
|
|
|
|
// typical code section alignment.
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol &Destination;
|
2018-03-30 06:32:13 +08:00
|
|
|
llvm::SmallVector<Defined *, 3> Syms;
|
2017-10-27 17:07:10 +08:00
|
|
|
uint64_t Offset = 0;
|
2017-07-18 19:59:19 +08:00
|
|
|
uint32_t Alignment = 4;
|
2016-07-09 00:10:27 +08:00
|
|
|
};
|
|
|
|
|
2017-02-01 18:26:03 +08:00
|
|
|
// For a Relocation to symbol S create a Thunk to be added to a synthetic
|
|
|
|
// ThunkSection. At present there are implementations for ARM and Mips Thunks.
|
2017-11-04 05:21:47 +08:00
|
|
|
Thunk *addThunk(RelType Type, Symbol &S);
|
2016-07-09 00:10:27 +08:00
|
|
|
|
|
|
|
} // namespace elf
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|