Questions tagged [got]

Global Offset Table (dynamic linking) FOR THE NODE.JS REQUEST LIBRARY USE [node.js-got]

For more, see

47 questions
20
votes
1 answer

Why does a fully static Rust ELF binary have a Global Offset Table (GOT) section?

This code, when compiled for the x86_64-unknown-linux-musl target, produces a .got section: fn main() { println!("Hello, world!"); } $ cargo build --release --target x86_64-unknown-linux-musl $ readelf -S hello There are 30 section headers,…
kreo
  • 2,613
  • 2
  • 19
  • 31
9
votes
2 answers

Why use the Global Offset Table for symbols defined in the shared library itself?

Consider the following simple shared library source code: library.cpp: static int global = 10; int foo() { return global; } Compiled with -fPIC option in clang, it results in this object assembly (x86-64): foo(): # @foo() push rbp mov rbp,…
yggdrasil
  • 737
  • 5
  • 14
8
votes
2 answers

How can two processes share the same Shared Library?

I've been trying to get a better grasp of how shared libraries work but I just can't rap my head around two things. 1- Each process has its own virtual memory space and page table, so If a shared library gets loaded into one process virtual memory…
8
votes
2 answers

What is <.got> section in ELF?

As far as I know, PLT and GOT are the section for handling dynamic linked function. If code calls printf which is libc's function, 1. Firstly it calls PLT to get printf's address. 2. And write this address into GOT section. 3. From second…
Jiwon
  • 1,074
  • 1
  • 11
  • 27
7
votes
1 answer

What does `var@GOTPCREL(%rip)` mean?

What does @GOTPCREL(%rip) mean? I've come across this line mov var@GOTPCREL(%rip), %rax and was a bit puzzled about the weird syntax. Can someone please recommend the relevant docs I should read to understand this? Thanks!
Curious Learner
  • 343
  • 2
  • 9
7
votes
1 answer

find address of PLT stub

I am working on Linux X86_64. I have a need to determine the address of a specific PLT entry in an ELF file given the name of the dynamic function that the entry represents. I can figure out the file offset from the address, but I need to be able to…
codemonkey
  • 161
  • 1
  • 9
4
votes
1 answer

Why is the `jmp` at the start of the PLT stub needed?

The way PLT usage is specified in the SystemV ABI (and implemented in practice), is schematically somtehing like this: # A call from somewhere in code is into a PLT slot # (In reality not a direct call, in x64 typically an rip-relative one) 0x500: …
Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101
4
votes
2 answers

undefined reference to `_GLOBAL_OFFSET_TABLE_' in gcc 32-bit code for a trivial function, freestanding OS

I have a small c code file(function.c): int function() { return 0x1234abce; } I am using a 64 bit machine. However, I want to write a small 32 bit OS. I want to compile the code into a 'pure' assembly/binary file. I compile my code with: gcc…
Suraaj K S
  • 600
  • 3
  • 21
4
votes
1 answer

How can each process have it's own copy of global data in a shared library

I understand that due to shared libraries not knowing where they will be placed by the dynamic loader, they have to rely on the GOT to resolve all references to global data. For example, a shared library has a global variable named globe, a possible…
GamefanA
  • 1,555
  • 2
  • 16
  • 23
3
votes
1 answer

Why does linux use two GOT sections in x64? .GOT vs .got.plt

I'm trying to figure out the difference between these two sections, this may appear to be a duplicate of this question, but the answer given there didn't explain a lot, so I'd like a more detailed and concise explanation.
Trey
  • 474
  • 2
  • 9
  • 32
3
votes
2 answers

Are changes made to the GOT expected to be reversed during reverse debugging?

Is it expected that changes made to a program's address space would not be reverted during reverse debugging? I have been debugging a program which segfaults when a pointer to strlen in the GOT becomes corrupted during the course of execution.…
user001
  • 1,850
  • 4
  • 27
  • 42
3
votes
1 answer

How to access a C global variable through GOT in GAS assembly on x86-64 Linux?

My problem I am trying to write a shared library(not an executable, so please do not tell me to use -no-pie) with assembly and C in separate files(not inline assembly). And I would like to access a C global variable through Global Offset Table in…
Alex Wang
  • 325
  • 2
  • 13
3
votes
1 answer

Why trampoline from PLT to GOT instead of directly jumping to GOT?

I'm studying how the GOT and PLT are used in dynamic linking. I'm confused about why each dynamically linked function call seems to jump to a position in the PLT which will always jump to the same position in the GOT. Why not just jump to that…
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
2
votes
0 answers

segfault on jump from PLT

I am trying to find the cause of a segfault, and narrowed it to the PLT using gdb's btrace. The segfault occurs during a jump from the PLT to the GOT, which I interpret to signify that the PLT became corrupted during execution. Based on the…
user001
  • 1,850
  • 4
  • 27
  • 42
2
votes
0 answers

How does GOT work when there are multiple shared libraries involved?

Let's say there are multiple shared libraries linked to an executable. Say libaaa.so makes a reference to a global variable aaa and libbbb.so makes a reference to a global variable bbb. My understanding is that the code accesses these variables…
Ziffusion
  • 8,779
  • 4
  • 29
  • 57
1
2 3 4