Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fbc: Add -nolib command line option #400

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Version 1.10.0
- gfxlib2: SCREENCONTROL: add getters for GL parameters - new GET_GL_* constants in fbgfx.bi
- Name mangling for c++ 'char' through BYTE/UBYTE parameters using the form "[unsigned] byte alias "char". Data type size is still 8 byte signed/unsigned from fbc side, but will mangled as 'char'; neither signed nor unsigned for the c++ side.
- Support 'SOURCE_DATE_EPOCH' environment variable for controlling the instrinsic __DATE__, __DATE_ISO__, __TIME__ macros. This in turn controls __FB_BUILD_DATE__ and __FB_BUILD_DATE_ISO__ macros when building the compiler. Report error message on malformed values.
- fbc -nolib a,b,c command line option for selectively excluding specific libraries when linking (more fine-grained control than -nodeflibs, and not only for default libraries)

[fixed]
- gas64: missing restoring of use of one virtual register on sqr for float (SARG)
Expand Down
5 changes: 4 additions & 1 deletion doc/fbc.1
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ Only show \fIn\fR errors
Use thread-safe FB runtime
.TP
\fB\-nodeflibs\fR
Do not include the default libraries
Do not include the default libraries when linking
.TP
\fB\-noerrline\fR
Do not show source context in error messages
.TP
\fB\-nolib\fR \fIa,b,c\fR
Do not include the specified libraries when linking
.TP
\fB\-noobjinfo\fR
Do not read/write compile-time info from/to .o and .a files
.TP
Expand Down
28 changes: 27 additions & 1 deletion src/compiler/fbc.bas
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type FBCCTX
libfiles as TLIST
libs as TSTRSET
libpaths as TSTRSET
excludedlibs as TSTRSET '' lib names explicitly excluded via -nodeflib option(s)

'' Final list of libs and paths for linking
'' (each module can have #inclibs and #libpaths and add more, and for
Expand Down Expand Up @@ -204,6 +205,7 @@ private sub fbcInit( )
strlistInit( @fbc.libfiles, FBC_INITFILES\4 )
strsetInit( @fbc.libs, FBC_INITFILES\4 )
strsetInit( @fbc.libpaths, FBC_INITFILES\4 )
strsetInit( @fbc.excludedlibs, FBC_INITFILES\4 )

strsetInit(@fbc.finallibs, FBC_INITFILES\2)
strsetInit(@fbc.finallibpaths, FBC_INITFILES\2)
Expand Down Expand Up @@ -1723,6 +1725,7 @@ enum
OPT_MT
OPT_NODEFLIBS
OPT_NOERRLINE
OPT_NOLIB
OPT_NOOBJINFO
OPT_NOSTRIP
OPT_O
Expand Down Expand Up @@ -1804,6 +1807,7 @@ dim shared as FBC_CMDLINE_OPTION cmdlineOptionTB(0 to (OPT__COUNT - 1)) = _
( FALSE, TRUE , FALSE, FALSE ), _ '' OPT_MT affects link, __FB_MT__
( FALSE, TRUE , FALSE, FALSE ), _ '' OPT_NODEFLIBS affects link
( FALSE, TRUE , FALSE, FALSE ), _ '' OPT_NOERRLINE affects compiler output display
( TRUE , TRUE , FALSE, FALSE ), _ '' OPT_NOLIB affects link
( FALSE, TRUE , FALSE, FALSE ), _ '' OPT_NOOBJINFO affects post compile process
( FALSE, TRUE , FALSE, FALSE ), _ '' OPT_NOSTRIP affects link
( TRUE , TRUE , FALSE, FALSE ), _ '' OPT_O affects input file naming
Expand Down Expand Up @@ -2061,6 +2065,15 @@ private sub handleOpt _
case OPT_NOERRLINE
fbSetOption( FB_COMPOPT_SHOWERROR, FALSE )

case OPT_NOLIB
dim libs() as string
hSplitStr(arg, ",", libs())
for i as integer = lbound(libs) to ubound(libs)
if len(libs(i)) > 0 then
strsetAdd(@fbc.excludedlibs, libs(i), 0 /'unused userdata'/)
end if
next

case OPT_NOOBJINFO
fbSetOption( FB_COMPOPT_OBJINFO, FALSE )

Expand Down Expand Up @@ -2387,6 +2400,7 @@ private function parseOption(byval opt as zstring ptr) as integer
case asc("n")
CHECK("noerrline", OPT_NOERRLINE)
CHECK("nodeflibs", OPT_NODEFLIBS)
CHECK("nolib", OPT_NOLIB)
CHECK("noobjinfo", OPT_NOOBJINFO)
CHECK("nostrip", OPT_NOSTRIP)

Expand Down Expand Up @@ -3990,6 +4004,15 @@ private sub hAddDefaultLibs( )

end sub

private sub hExcludeLibsFromLink( )
'' Remove any excluded libs from fbc.finallibs list
dim as TSTRSETITEM ptr i = listGetHead(@fbc.excludedlibs.list)
while i
strsetDel(@fbc.finallibs, i->s)
i = listGetNext(i)
wend
end sub

private sub hPrintOptions( byval verbose as integer )
'' Note: must print each line separately to let the rtlib print the
'' proper line endings even if redirected to file/pipe, hard-coding \n
Expand Down Expand Up @@ -4056,8 +4079,9 @@ private sub hPrintOptions( byval verbose as integer )
print " -map <file> Save linking map to file"
print " -maxerr <n> Only show <n> errors"
print " -mt Use thread-safe FB runtime"
print " -nodeflibs Do not include the default libraries"
print " -nodeflibs Do not include the default libraries when linking"
print " -noerrline Do not show source context in error messages"
print " -nolib <a,b,c> Do not include the specified libraries when linking"
print " -noobjinfo Do not read/write compile-time info from/to .o and .a files"
print " -nostrip Do not strip symbol information from the output file"
print " -o <file> Set .o (or -pp .bas) file name for prev/next input file"
Expand Down Expand Up @@ -4310,6 +4334,8 @@ end sub
hAddDefaultLibs( )
end if

hExcludeLibsFromLink( )

if( hLinkFiles( ) = FALSE ) then
fbcEnd( 1 )
end if
Expand Down
41 changes: 40 additions & 1 deletion src/compiler/hash.bas
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,53 @@ sub strsetAdd _
i = listNewNode( @set->list )
i->s = s
i->userdata = userdata
i->hashitem = NULL

'' Don't bother with empty strings
'' (ditto, but won't happen here as long as not out of memory)
if( len( i->s ) = 0 ) then
exit sub
end if

hashAdd(@set->hash, strptr(i->s), i, hashHash(strptr(i->s)))
i->hashitem = hashAdd( @set->hash, i->s, i, hashHash( i->s ))
end sub

sub strsetDel(byval set as TSTRSET ptr, byref s as const string)
if len(s) = 0 then
return
end if

'' Remove from hash table
var index = hashHash(s)
dim as TSTRSETITEM ptr setitem = hashLookupEx(@set->hash, s, index)
if setitem then
hashDel(@set->hash, setitem->hashitem, index)
setitem->hashitem = NULL

'' Remove corresponding entry from list
dim as TSTRSETITEM ptr i = listGetHead(@set->list)
while i
if i = setitem then
i->s = ""
listDelNode(@set->list, i)
exit while
end if
i = listGetNext(i)
wend
end if

'' Remove any other entries from list
'' (usually there shouldn't be any, but strsetAdd() has a code path
'' which adds entries to the list only...)
dim as TSTRSETITEM ptr i = listGetHead(@set->list)
while i
if i->s = s then
i->s = ""
listDelNode(@set->list, i)
exit while
end if
i = listGetNext(i)
wend
end sub

sub strsetCopy(byval target as TSTRSET ptr, byval source as TSTRSET ptr)
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/hash.bi
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ declare sub hashDel _
type TSTRSETITEM
as string s
as integer userdata
as HASHITEM ptr hashitem
end type

type TSTRSET
Expand All @@ -79,6 +80,7 @@ declare sub strsetAdd _
byref s as string, _
byval userdata as integer _
)
declare sub strsetDel(byval set as TSTRSET ptr, byref s as const string)
declare sub strsetCopy(byval target as TSTRSET ptr, byval source as TSTRSET ptr)
declare sub strsetInit(byval set as TSTRSET ptr, byval nodes as integer)
declare sub strsetEnd(byval set as TSTRSET ptr)
Expand Down