LLVM backend for 6502
Go to file
Jason W Kim 861b9c6a39 This fixes one divergence between LLVM and binutils for ARM in the
text section.

Assume the following bit of annotated assembly:

.section	.data.rel.ro,"aw",%progbits
.align	2
.LAlpha:
.long	startval(GOTOFF)

.text
.align	2
.type	main,%function
.align	4

main: ;;; assume "main" starts at offset 0x20
0x0	push	{r11, lr}
0x4	movw	r0, :lower16:(.LAlpha-(.LBeta+8))
;;; ==> (.AddrOf(.LAlpha) - ((.AddrOf(.LBeta) - .AddrOf(".")) + 8)
;;; ==> (??? - ((16-4) + 8) = -20
0x8	movt	r0, :upper16:(.LAlpha-(.LBeta+8))
;;; ==> (.AddrOf(.LAlpha) - ((.AddrOf(.LBeta) - .AddrOf(".")) + 8)
;;; ==> (??? - ((16-8) + 8) = -16
0xc	... blah

.LBeta:
0x10	add	r0, pc, r0
0x14	... blah

.LGamma:
0x18	add	r1, pc, r1

Above snippet results in the following relocs in the .o file for the
first pair of movw/movt instructions

00000024 R_ARM_MOVW_PREL_NC .LAlpha
00000028 R_ARM_MOVT_PREL .LAlpha

And the encoded instructions in the .o file for main: must be

00000020 <main>:
20:	e92d4800 push	{fp, lr}
24:	e30f0fec movw	r0, #65516	; 0xffec i.e. -20
28:	e34f0ff0 movt	r0, #65520	; 0xfff0 i.e. -16

However, llc (prior to this commit) generates the following sequence

00000020 <main>:
20:	e92d4800 push	{fp, lr}
24:	e30f0fec movw	r0, #65516	; 0xffec - i.e. -20
28:	e34f0fff movt	r0, #65535	; 0xffff - i.e. -1

What has to happen in the ArmAsmBackend is that if the relocation is PC
relative, the 16 bits encoded as part of movw and movt must be both addends,
not addresses. It makes sense to encode addresses by right shifting the value
by 16, but the result is incorrect for PIC.
i.e., the right shift by 16 for movt is ONLY valid for the NON-PCRel case.

This change agrees with what GNU as does, and makes the PIC code run.

MC/ARM/elf-movt.s covers this case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131674 91177308-0d34-0410-b5e6-96231b3b80d8
2011-05-19 20:55:25 +00:00
autoconf Re-add the autoconf rule for the docs/doxygen.cfg file. 2011-05-13 03:27:56 +00:00
bindings Fix compiling the ocaml kaleidoscope tutorials 2011-02-09 18:32:02 +00:00
cmake Another try at fixing cmake. 2011-05-19 00:13:04 +00:00
docs Correct typos in TestingGuide.html 2011-05-18 18:07:16 +00:00
examples Fix a ton of comment typos found by codespell. Patch by 2011-04-15 05:18:47 +00:00
include Implement the Win64 EH prolog instruction methods on the base MCStreamer. 2011-05-19 19:35:55 +00:00
lib This fixes one divergence between LLVM and binutils for ARM in the 2011-05-19 20:55:25 +00:00
projects Fix a ton of comment typos found by codespell. Patch by 2011-04-15 05:18:47 +00:00
runtime The computation of string length is not that complicated. Fix it, again. :) 2011-05-05 23:52:18 +00:00
test This fixes one divergence between LLVM and binutils for ARM in the 2011-05-19 20:55:25 +00:00
tools CMake builds gold by default since revision 127466. This is 2011-05-12 11:26:21 +00:00
unittests Teach getCastOpcode about element-by-element vector casts. For example, "trunc" 2011-05-18 07:13:41 +00:00
utils In r131488 I misunderstood how VREV works. It splits the vector in half and splits each half. Therefore, the real problem was that we were using a VREV64 for a 4xi16, when we should have been using a VREV32. 2011-05-18 06:42:21 +00:00
website
.gitignore Cleanup and document .gitignore. 2010-12-17 17:22:50 +00:00
build-for-llvm-top.sh Patch to build llvm with srcdir != objdir from 2009-01-23 08:42:38 +00:00
CMakeLists.txt Rename profile_rt.so to libprofile_rt.so under configure+make (it already was 2011-04-29 02:12:06 +00:00
configure Re-add the autoconf rule for the docs/doxygen.cfg file. 2011-05-13 03:27:56 +00:00
CREDITS.TXT Another git svn dcommit test. This time let's hope it doesn't kill my repo. 2010-12-10 14:45:10 +00:00
LICENSE.TXT 2010 is upon us. 2010-01-09 18:40:31 +00:00
llvm.spec.in
Makefile build: Add support for a SHOW_DIAGNOSTICS build variable. 2011-04-11 22:37:39 +00:00
Makefile.common Removed trailing whitespace from Makefiles. 2009-01-09 16:44:42 +00:00
Makefile.config.in autoconf: Add --disable-embed-stdcxx to suppress linking libstdc++.a into llvm.dll with --enable-shared on Cygming. 2010-12-29 03:59:14 +00:00
Makefile.rules Fix a ton of comment typos found by codespell. Patch by 2011-04-15 05:18:47 +00:00
ModuleInfo.txt Remove trailing space. This is just an excuse to poke the 2010-10-05 20:32:15 +00:00
README.txt reverting test commit 2011-05-12 17:38:08 +00:00

Low Level Virtual Machine (LLVM)
================================

This directory and its subdirectories contain source code for the Low Level
Virtual Machine, a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the HTML documentation provided in docs/index.html for further
assistance with LLVM.

If you're writing a package for LLVM, see docs/Packaging.html for our
suggestions.