Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
2aceea63
Commit
2aceea63
authored
Apr 07, 2011
by
Mikkel Krautz
Committed by
Russ Cox
Apr 07, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ld: fix Mach-O X86_64_RELOC_SIGNED relocations
Fixes #1658. R=rsc CC=golang-dev
https://golang.org/cl/4344066
parent
cf3323f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
+24
-2
ldmacho.c
src/cmd/ld/ldmacho.c
+24
-2
No files found.
src/cmd/ld/ldmacho.c
View file @
2aceea63
...
...
@@ -422,6 +422,7 @@ void
ldmacho
(
Biobuf
*
f
,
char
*
pkg
,
int64
len
,
char
*
pn
)
{
int
i
,
j
,
is64
;
uint64
secaddr
;
uchar
hdr
[
7
*
4
],
*
cmdp
;
uchar
tmp
[
4
];
uchar
*
dat
;
...
...
@@ -754,8 +755,29 @@ ldmacho(Biobuf *f, char *pkg, int64 len, char *pn)
rp
->
siz
=
rel
->
length
;
rp
->
type
=
512
+
(
rel
->
type
<<
1
)
+
rel
->
pcrel
;
rp
->
off
=
rel
->
addr
;
rp
->
add
=
e
->
e32
(
s
->
p
+
rp
->
off
);
// Handle X86_64_RELOC_SIGNED referencing a section (rel->extrn == 0).
if
(
thechar
==
'6'
&&
rel
->
extrn
==
0
&&
rel
->
type
==
1
)
{
// Calculate the addend as the offset into the section.
//
// The rip-relative offset stored in the object file is encoded
// as follows:
//
// movsd 0x00000360(%rip),%xmm0
//
// To get the absolute address of the value this rip-relative address is pointing
// to, we must add the address of the next instruction to it. This is done by
// taking the address of the relocation and adding 4 to it (since the rip-relative
// offset can at most be 32 bits long). To calculate the offset into the section the
// relocation is referencing, we subtract the vaddr of the start of the referenced
// section found in the original object file.
//
// [For future reference, see Darwin's /usr/include/mach-o/x86_64/reloc.h]
secaddr
=
c
->
seg
.
sect
[
rel
->
symnum
-
1
].
addr
;
rp
->
add
=
e
->
e32
(
s
->
p
+
rp
->
off
)
+
rp
->
off
+
4
-
secaddr
;
}
else
rp
->
add
=
e
->
e32
(
s
->
p
+
rp
->
off
);
// For i386 Mach-O PC-relative, the addend is written such that
// it *is* the PC being subtracted. Use that to make
// it match our version of PC-relative.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment