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
jberryman
GHC
Commits
a48bee9f
Commit
a48bee9f
authored
Dec 04, 2014
by
Simon Marlow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Revert "Add purgeObj() to remove the symbol table entries for an object""
This reverts commit
7932b2ad
.
parent
55a2a0b4
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
24 deletions
+92
-24
includes/rts/Linker.h
includes/rts/Linker.h
+3
-0
rts/Linker.c
rts/Linker.c
+51
-23
testsuite/tests/rts/linker_unload.c
testsuite/tests/rts/linker_unload.c
+37
-0
testsuite/tests/rts/linker_unload.stdout
testsuite/tests/rts/linker_unload.stdout
+1
-1
No files found.
includes/rts/Linker.h
View file @
a48bee9f
...
@@ -51,6 +51,9 @@ void *lookupSymbol( char *lbl );
...
@@ -51,6 +51,9 @@ void *lookupSymbol( char *lbl );
/* delete an object from the pool */
/* delete an object from the pool */
HsInt
unloadObj
(
pathchar
*
path
);
HsInt
unloadObj
(
pathchar
*
path
);
/* purge an object's symbols from the symbol table, but don't unload it */
HsInt
purgeObj
(
pathchar
*
path
);
/* add an obj (populate the global symbol table, but don't resolve yet) */
/* add an obj (populate the global symbol table, but don't resolve yet) */
HsInt
loadObj
(
pathchar
*
path
);
HsInt
loadObj
(
pathchar
*
path
);
...
...
rts/Linker.c
View file @
a48bee9f
...
@@ -2282,20 +2282,45 @@ mmap_again:
...
@@ -2282,20 +2282,45 @@ mmap_again:
}
}
#endif // USE_MMAP
#endif // USE_MMAP
/*
* Remove symbols from the symbol table, and free oc->symbols.
* This operation is idempotent.
*/
static
void
removeOcSymbols
(
ObjectCode
*
oc
)
static
void
removeOcSymbols
(
ObjectCode
*
oc
)
{
{
if
(
oc
->
symbols
==
NULL
)
return
;
if
(
oc
->
symbols
==
NULL
)
return
;
/* Remove all the mappings for the symbols within this object..
// Remove all the mappings for the symbols within this object..
*/
int
i
;
int
i
;
for
(
i
=
0
;
i
<
oc
->
n_symbols
;
i
++
)
{
for
(
i
=
0
;
i
<
oc
->
n_symbols
;
i
++
)
{
if
(
oc
->
symbols
[
i
]
!=
NULL
)
{
if
(
oc
->
symbols
[
i
]
!=
NULL
)
{
ghciRemoveSymbolTable
(
symhash
,
oc
->
symbols
[
i
],
oc
);
ghciRemoveSymbolTable
(
symhash
,
oc
->
symbols
[
i
],
oc
);
}
}
}
}
stgFree
(
oc
->
symbols
);
oc
->
symbols
=
NULL
;
}
/*
* Release StablePtrs and free oc->stable_ptrs.
* This operation is idempotent.
*/
static
void
freeOcStablePtrs
(
ObjectCode
*
oc
)
{
// Release any StablePtrs that were created when this
// object module was initialized.
ForeignExportStablePtr
*
fe_ptr
,
*
next
;
for
(
fe_ptr
=
oc
->
stable_ptrs
;
fe_ptr
!=
NULL
;
fe_ptr
=
next
)
{
next
=
fe_ptr
->
next
;
freeStablePtr
(
fe_ptr
->
stable_ptr
);
stgFree
(
fe_ptr
);
}
oc
->
stable_ptrs
=
NULL
;
}
}
/*
/*
* freeObjectCode() releases all the pieces of an ObjectCode. It is called by
* freeObjectCode() releases all the pieces of an ObjectCode. It is called by
* the GC when a previously unloaded ObjectCode has been determined to be
* the GC when a previously unloaded ObjectCode has been determined to be
...
@@ -3042,6 +3067,7 @@ static HsInt loadObj_ (pathchar *path)
...
@@ -3042,6 +3067,7 @@ static HsInt loadObj_ (pathchar *path)
if
(
!
loadOc
(
oc
))
{
if
(
!
loadOc
(
oc
))
{
// failed; free everything we've allocated
// failed; free everything we've allocated
removeOcSymbols
(
oc
);
removeOcSymbols
(
oc
);
// no need to freeOcStablePtrs, they aren't created until resolveObjs()
freeObjectCode
(
oc
);
freeObjectCode
(
oc
);
return
0
;
return
0
;
}
}
...
@@ -3177,7 +3203,7 @@ HsInt resolveObjs (void)
...
@@ -3177,7 +3203,7 @@ HsInt resolveObjs (void)
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
* delete an object from the pool
* delete an object from the pool
*/
*/
static
HsInt
unloadObj_
(
pathchar
*
path
)
static
HsInt
unloadObj_
(
pathchar
*
path
,
rtsBool
just_purge
)
{
{
ObjectCode
*
oc
,
*
prev
,
*
next
;
ObjectCode
*
oc
,
*
prev
,
*
next
;
HsBool
unloadedAnyObj
=
HS_BOOL_FALSE
;
HsBool
unloadedAnyObj
=
HS_BOOL_FALSE
;
...
@@ -3193,30 +3219,24 @@ static HsInt unloadObj_ (pathchar *path)
...
@@ -3193,30 +3219,24 @@ static HsInt unloadObj_ (pathchar *path)
if
(
!
pathcmp
(
oc
->
fileName
,
path
))
{
if
(
!
pathcmp
(
oc
->
fileName
,
path
))
{
// these are both idempotent, so in just_purge mode we can
// later call unloadObj() to really unload the object.
removeOcSymbols
(
oc
);
removeOcSymbols
(
oc
);
freeOcStablePtrs
(
oc
);
if
(
prev
==
NULL
)
{
if
(
!
just_purge
)
{
objects
=
oc
->
next
;
if
(
prev
==
NULL
)
{
}
else
{
objects
=
oc
->
next
;
prev
->
next
=
oc
->
next
;
}
else
{
}
prev
->
next
=
oc
->
next
;
oc
->
next
=
unloaded_objects
;
unloaded_objects
=
oc
;
// Release any StablePtrs that were created when this
// object module was initialized.
{
ForeignExportStablePtr
*
fe_ptr
,
*
next
;
for
(
fe_ptr
=
oc
->
stable_ptrs
;
fe_ptr
!=
NULL
;
fe_ptr
=
next
)
{
next
=
fe_ptr
->
next
;
freeStablePtr
(
fe_ptr
->
stable_ptr
);
stgFree
(
fe_ptr
);
}
}
oc
->
next
=
unloaded_objects
;
unloaded_objects
=
oc
;
oc
->
status
=
OBJECT_UNLOADED
;
}
else
{
prev
=
oc
;
}
}
oc
->
status
=
OBJECT_UNLOADED
;
/* This could be a member of an archive so continue
/* This could be a member of an archive so continue
* unloading other members. */
* unloading other members. */
unloadedAnyObj
=
HS_BOOL_TRUE
;
unloadedAnyObj
=
HS_BOOL_TRUE
;
...
@@ -3237,7 +3257,15 @@ static HsInt unloadObj_ (pathchar *path)
...
@@ -3237,7 +3257,15 @@ static HsInt unloadObj_ (pathchar *path)
HsInt
unloadObj
(
pathchar
*
path
)
HsInt
unloadObj
(
pathchar
*
path
)
{
{
ACQUIRE_LOCK
(
&
linker_mutex
);
ACQUIRE_LOCK
(
&
linker_mutex
);
HsInt
r
=
unloadObj_
(
path
);
HsInt
r
=
unloadObj_
(
path
,
rtsFalse
);
RELEASE_LOCK
(
&
linker_mutex
);
return
r
;
}
HsInt
purgeObj
(
pathchar
*
path
)
{
ACQUIRE_LOCK
(
&
linker_mutex
);
HsInt
r
=
unloadObj_
(
path
,
rtsTrue
);
RELEASE_LOCK
(
&
linker_mutex
);
RELEASE_LOCK
(
&
linker_mutex
);
return
r
;
return
r
;
}
}
...
...
testsuite/tests/rts/linker_unload.c
View file @
a48bee9f
...
@@ -87,4 +87,41 @@ int main (int argc, char *argv[])
...
@@ -87,4 +87,41 @@ int main (int argc, char *argv[])
printf
(
"%d "
,
i
);
printf
(
"%d "
,
i
);
fflush
(
stdout
);
fflush
(
stdout
);
}
}
for
(
i
=
0
;
i
<
ITERATIONS
;
i
++
)
{
r
=
loadObj
(
OBJPATH
);
if
(
!
r
)
{
errorBelch
(
"loadObj(%s) failed"
,
OBJPATH
);
exit
(
1
);
}
r
=
resolveObjs
();
if
(
!
r
)
{
errorBelch
(
"resolveObjs failed"
);
exit
(
1
);
}
#if LEADING_UNDERSCORE
f
=
lookupSymbol
(
"_f"
);
#else
f
=
lookupSymbol
(
"f"
);
#endif
if
(
!
f
)
{
errorBelch
(
"lookupSymbol failed"
);
exit
(
1
);
}
r
=
f
(
3
);
if
(
r
!=
4
)
{
errorBelch
(
"call failed; %d"
,
r
);
exit
(
1
);
}
// check that we can purge first, then unload
purgeObj
(
OBJPATH
);
performMajorGC
();
unloadObj
(
OBJPATH
);
performMajorGC
();
printf
(
"%d "
,
i
);
fflush
(
stdout
);
}
hs_exit
();
exit
(
0
);
}
}
testsuite/tests/rts/linker_unload.stdout
View file @
a48bee9f
This diff is collapsed.
Click to expand it.
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