Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tobias Decking
GHC
Commits
4caf239d
Commit
4caf239d
authored
Dec 10, 2010
by
benl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Defensify naked read in LLVM mangler
parent
157161ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
10 deletions
+27
-10
compiler/llvmGen/LlvmMangler.hs
compiler/llvmGen/LlvmMangler.hs
+27
-10
No files found.
compiler/llvmGen/LlvmMangler.hs
View file @
4caf239d
...
...
@@ -19,8 +19,11 @@ import qualified Data.ByteString.Char8 as BS
import
LlvmCodeGen.Ppr
(
infoSection
,
iTableSuf
)
import
Data.Char
import
Outputable
import
Util
{- Configuration. -}
newSection
,
oldSection
,
functionSuf
,
tableSuf
,
funDivider
,
eol
::
ByteString
newSection
=
BS
.
pack
"
\n
.text
\n
"
...
...
@@ -161,10 +164,11 @@ replaceSection sec =
fixupStack
::
ByteString
->
ByteString
->
ByteString
fixupStack
fun
nfun
|
BS
.
null
nfun
=
let
-- fixup sub op
(
a
,
b
)
=
BS
.
breakSubstring
(
BS
.
pack
", %esp
\n
"
)
fun
(
a'
,
num
)
=
BS
.
breakEnd
dollarPred
a
num'
=
BS
.
pack
$
show
(
read
(
BS
.
unpack
num
)
+
4
::
Int
)
fix
=
a'
`
BS
.
append
`
num'
(
a
,
b
)
=
BS
.
breakSubstring
(
BS
.
pack
", %esp
\n
"
)
fun
(
a'
,
strNum
)
=
BS
.
breakEnd
dollarPred
a
Just
num
=
readInt
(
BS
.
unpack
strNum
)
num'
=
BS
.
pack
$
show
(
num
+
4
::
Int
)
fix
=
a'
`
BS
.
append
`
num'
in
if
BS
.
null
b
then
nfun
`
BS
.
append
`
a
else
fixupStack
b
(
nfun
`
BS
.
append
`
fix
)
...
...
@@ -174,15 +178,28 @@ fixupStack fun nfun =
(
a
,
b
)
=
BS
.
breakSubstring
(
BS
.
pack
"jmp"
)
fun
-- We need to avoid processing jumps to labels, they are of the form:
-- jmp\tL..., jmp\t_f..., jmpl\t_f..., jmpl\t*%eax...
labelJump
=
BS
.
index
b
4
==
'L'
(
jmp
,
b'
)
=
BS
.
break
eolPred
b
(
a'
,
numx
)
=
BS
.
breakEnd
dollarPred
a
(
num
,
x
)
=
BS
.
break
commaPred
numx
num'
=
BS
.
pack
$
show
(
read
(
BS
.
unpack
num
)
+
4
::
Int
)
fix
=
a'
`
BS
.
append
`
num'
`
BS
.
append
`
x
`
BS
.
append
`
jmp
labelJump
=
BS
.
index
b
4
==
'L'
(
jmp
,
b'
)
=
BS
.
break
eolPred
b
(
a'
,
numx
)
=
BS
.
breakEnd
dollarPred
a
(
strNum
,
x
)
=
BS
.
break
commaPred
numx
Just
num
=
readInt
(
BS
.
unpack
strNum
)
num'
=
BS
.
pack
$
show
(
num
+
4
::
Int
)
fix
=
a'
`
BS
.
append
`
num'
`
BS
.
append
`
x
`
BS
.
append
`
jmp
in
if
BS
.
null
b
then
nfun
`
BS
.
append
`
a
else
if
labelJump
then
fixupStack
b'
(
nfun
`
BS
.
append
`
a
`
BS
.
append
`
jmp
)
else
fixupStack
b'
(
nfun
`
BS
.
append
`
fix
)
-- | 'read' is one of my least favourite functions.
readInt
::
String
->
Maybe
Int
readInt
str
|
not
$
null
$
filter
(
not
.
isDigit
)
str
=
pprTrace
"LLvmMangler"
(
text
"Cannot read"
<+>
text
(
show
str
)
<+>
text
"as it's not an Int"
)
Nothing
|
otherwise
=
Just
$
read
str
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