I want to run llvm-slicer (source) for PostgreSQL main executable file (i.e., PG_ROOT/src/backend/postgres) to carry backward slicing on PostgreSQL.
llvm-slicer runs on top of bitcode (.bc file). I have compiled PostgreSQL via ./configure CC=clang-6.0 && make CC=clang-6.0, duiring which, the final compile command that link many .o files together is (very long):
clang-6.0 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -O2 access/brin/brin.o access/brin/brin_pageops.o access/brin/brin_revmap.o access/brin/brin_tuple.o access/brin/brin_xlog.o access/brin/brin_minmax.o access/brin/brin_inclusion.o access/brin/brin_validate.o access/common/bufmask.o access/common/heaptuple.o access/common/indextuple.o access/common/printsimple.o access/common/printtup.o access/common/relation.o access/common/reloptions.o access/common/scankey.o access/common/session.o access/common/tupconvert.o access/common/tupdesc.o access/gin/ginutil.o access/gin/gininsert.o access/gin/ginxlog.o access/gin/ginentrypage.o access/gin/gindatapage.o access/gin/ginbtree.o access/gin/ginscan.o access/gin/ginget.o access/gin/ginvacuum.o access/gin/ginarrayproc.o access/gin/ginbulk.o access/gin/ginfast.o access/gin/ginpostinglist.o access/gin/ginlogic.o access/gin/ginvalidate.o access/gist/gist.o access/gist/gistutil.o access/gist/gistxlog.o access/gist/gistvacuum.o access/gist/gistget.o access/gist/gistscan.o access/gist/gistproc.o access/gist/gistsplit.o access/gist/gistbuild.o access/gist/gistbuildbuffers.o access/gist/gistvalidate.o access/hash/hash.o access/hash/hashfunc.o access/hash/hashinsert.o access/hash/hashovfl.o access/hash/hashpage.o access/hash/hashsearch.o access/hash/hashsort.o access/hash/hashutil.o access/hash/hashvalidate.o access/hash/hash_xlog.o access/heap/heapam.o access/heap/heapam_handler.o access/heap/heapam_visibility.o access/heap/hio.o access/heap/pruneheap.o access/heap/rewriteheap.o access/heap/syncscan.o access/heap/tuptoaster.o access/heap/vacuumlazy.o access/heap/visibilitymap.o access/index/amapi.o access/index/amvalidate.o access/index/genam.o access/index/indexam.o access/nbtree/nbtcompare.o access/nbtree/nbtinsert.o access/nbtree/nbtpage.o access/nbtree/nbtree.o access/nbtree/nbtsearch.o access/nbtree/nbtsplitloc.o access/nbtree/nbtutils.o access/nbtree/nbtsort.o access/nbtree/nbtvalidate.o access/nbtree/nbtxlog.o access/rmgrdesc/brindesc.o access/rmgrdesc/clogdesc.o access/rmgrdesc/committsdesc.o access/rmgrdesc/dbasedesc.o access/rmgrdesc/genericdesc.o access/rmgrdesc/gindesc.o access/rmgrdesc/gistdesc.o access/rmgrdesc/hashdesc.o access/rmgrdesc/heapdesc.o access/rmgrdesc/logicalmsgdesc.o access/rmgrdesc/mxactdesc.o access/rmgrdesc/nbtdesc.o access/rmgrdesc/relmapdesc.o access/rmgrdesc/replorigindesc.o access/rmgrdesc/seqdesc.o access/rmgrdesc/smgrdesc.o access/rmgrdesc/spgdesc.o access/rmgrdesc/standbydesc.o access/rmgrdesc/tblspcdesc.o access/rmgrdesc/xactdesc.o access/rmgrdesc/xlogdesc.o access/spgist/spgutils.o access/spgist/spginsert.o access/spgist/spgscan.o access/spgist/spgvacuum.o access/spgist/spgvalidate.o access/spgist/spgdoinsert.o access/spgist/spgxlog.o access/spgist/spgtextproc.o access/spgist/spgquadtreeproc.o access/spgist/spgkdtreeproc.o access/spgist/spgproc.o access/table/table.o access/table/tableam.o access/table/tableamapi.o access/tablesample/bernoulli.o access/tablesample/system.o access/tablesample/tablesample.o access/transam/clog.o access/transam/commit_ts.o access/transam/generic_xlog.o access/transam/multixact.o access/transam/parallel.o access/transam/rmgr.o access/transam/slru.o access/transam/subtrans.o access/transam/timeline.o access/transam/transam.o access/transam/twophase.o access/transam/twophase_rmgr.o access/transam/varsup.o access/transam/xact.o access/transam/xlog.o access/transam/xlogarchive.o access/transam/xlogfuncs.o access/transam/xloginsert.o access/transam/xlogreader.o access/transam/xlogutils.o bootstrap/bootparse.o bootstrap/bootstrap.o catalog/catalog.o catalog/dependency.o catalog/heap.o catalog/index.o catalog/indexing.o catalog/namespace.o catalog/aclchk.o catalog/objectaccess.o catalog/objectaddress.o catalog/partition.o catalog/pg_aggregate.o catalog/pg_collation.o catalog/pg_constraint.o catalog/pg_conversion.o catalog/pg_depend.o catalog/pg_enum.o catalog/pg_inherits.o catalog/pg_largeobject.o catalog/pg_namespace.o catalog/pg_operator.o catalog/pg_proc.o catalog/pg_publication.o catalog/pg_range.o catalog/pg_db_role_setting.o catalog/pg_shdepend.o catalog/pg_subscription.o catalog/pg_type.o catalog/storage.o catalog/toasting.o parser/analyze.o parser/gram.o parser/scan.o parser/parser.o parser/parse_agg.o parser/parse_clause.o parser/parse_coerce.o parser/parse_collate.o parser/parse_cte.o parser/parse_enr.o parser/parse_expr.o parser/parse_func.o parser/parse_node.o parser/parse_oper.o parser/parse_param.o parser/parse_relation.o parser/parse_target.o parser/parse_type.o parser/parse_utilcmd.o parser/scansup.o commands/amcmds.o commands/aggregatecmds.o commands/alter.o commands/analyze.o commands/async.o commands/cluster.o commands/comment.o commands/collationcmds.o commands/constraint.o commands/conversioncmds.o commands/copy.o commands/createas.o commands/dbcommands.o commands/define.o commands/discard.o commands/dropcmds.o commands/event_trigger.o commands/explain.o commands/extension.o commands/foreigncmds.o commands/functioncmds.o commands/indexcmds.o commands/lockcmds.o commands/matview.o commands/operatorcmds.o commands/opclasscmds.o commands/policy.o commands/portalcmds.o commands/prepare.o commands/proclang.o commands/publicationcmds.o commands/schemacmds.o commands/seclabel.o commands/sequence.o commands/statscmds.o commands/subscriptioncmds.o commands/tablecmds.o commands/tablespace.o commands/trigger.o commands/tsearchcmds.o commands/typecmds.o commands/user.o commands/vacuum.o commands/variable.o commands/view.o executor/execAmi.o executor/execCurrent.o executor/execExpr.o executor/execExprInterp.o executor/execGrouping.o executor/execIndexing.o executor/execJunk.o executor/execMain.o executor/execParallel.o executor/execPartition.o executor/execProcnode.o executor/execReplication.o executor/execScan.o executor/execSRF.o executor/execTuples.o executor/execUtils.o executor/functions.o executor/instrument.o executor/nodeAppend.o executor/nodeAgg.o executor/nodeBitmapAnd.o executor/nodeBitmapOr.o executor/nodeBitmapHeapscan.o executor/nodeBitmapIndexscan.o executor/nodeCustom.o executor/nodeFunctionscan.o executor/nodeGather.o executor/nodeHash.o executor/nodeHashjoin.o executor/nodeIndexscan.o executor/nodeIndexonlyscan.o executor/nodeLimit.o executor/nodeLockRows.o executor/nodeGatherMerge.o executor/nodeMaterial.o executor/nodeMergeAppend.o executor/nodeMergejoin.o executor/nodeModifyTable.o executor/nodeNestloop.o executor/nodeProjectSet.o executor/nodeRecursiveunion.o executor/nodeResult.o executor/nodeSamplescan.o executor/nodeSeqscan.o executor/nodeSetOp.o executor/nodeSort.o executor/nodeUnique.o executor/nodeValuesscan.o executor/nodeCtescan.o executor/nodeNamedtuplestorescan.o executor/nodeWorktablescan.o executor/nodeGroup.o executor/nodeSubplan.o executor/nodeSubqueryscan.o executor/nodeTidscan.o executor/nodeForeignscan.o executor/nodeWindowAgg.o executor/tstoreReceiver.o executor/tqueue.o executor/spi.o executor/nodeTableFuncscan.o foreign/foreign.o lib/binaryheap.o lib/bipartite_match.o lib/bloomfilter.o lib/dshash.o lib/hyperloglog.o lib/ilist.o lib/integerset.o lib/knapsack.o lib/pairingheap.o lib/rbtree.o lib/stringinfo.o libpq/be-fsstubs.o libpq/be-secure.o libpq/be-secure-common.o libpq/auth.o libpq/crypt.o libpq/hba.o libpq/ifaddr.o libpq/pqcomm.o libpq/pqformat.o libpq/pqmq.o libpq/pqsignal.o libpq/auth-scram.o main/main.o nodes/nodeFuncs.o nodes/nodes.o nodes/list.o nodes/bitmapset.o nodes/tidbitmap.o nodes/copyfuncs.o nodes/equalfuncs.o nodes/extensible.o nodes/makefuncs.o nodes/outfuncs.o nodes/readfuncs.o nodes/print.o nodes/read.o nodes/params.o nodes/value.o optimizer/geqo/geqo_copy.o optimizer/geqo/geqo_eval.o optimizer/geqo/geqo_main.o optimizer/geqo/geqo_misc.o optimizer/geqo/geqo_mutation.o optimizer/geqo/geqo_pool.o optimizer/geqo/geqo_random.o optimizer/geqo/geqo_recombination.o optimizer/geqo/geqo_selection.o optimizer/geqo/geqo_erx.o optimizer/geqo/geqo_pmx.o optimizer/geqo/geqo_cx.o optimizer/geqo/geqo_px.o optimizer/geqo/geqo_ox1.o optimizer/geqo/geqo_ox2.o optimizer/path/allpaths.o optimizer/path/clausesel.o optimizer/path/costsize.o optimizer/path/equivclass.o optimizer/path/indxpath.o optimizer/path/joinpath.o optimizer/path/joinrels.o optimizer/path/pathkeys.o optimizer/path/tidpath.o optimizer/plan/analyzejoins.o optimizer/plan/createplan.o optimizer/plan/initsplan.o optimizer/plan/planagg.o optimizer/plan/planmain.o optimizer/plan/planner.o optimizer/plan/setrefs.o optimizer/plan/subselect.o optimizer/prep/prepjointree.o optimizer/prep/prepqual.o optimizer/prep/preptlist.o optimizer/prep/prepunion.o optimizer/util/appendinfo.o optimizer/util/clauses.o optimizer/util/inherit.o optimizer/util/joininfo.o optimizer/util/orclauses.o optimizer/util/paramassign.o optimizer/util/pathnode.o optimizer/util/placeholder.o optimizer/util/plancat.o optimizer/util/predtest.o optimizer/util/relnode.o optimizer/util/restrictinfo.o optimizer/util/tlist.o optimizer/util/var.o partitioning/partbounds.o partitioning/partdesc.o partitioning/partprune.o port/atomics.o port/pg_sema.o port/pg_shmem.o postmaster/autovacuum.o postmaster/bgworker.o postmaster/bgwriter.o postmaster/checkpointer.o postmaster/fork_process.o postmaster/pgarch.o postmaster/pgstat.o postmaster/postmaster.o postmaster/startup.o postmaster/syslogger.o postmaster/walwriter.o regex/regcomp.o regex/regerror.o regex/regexec.o regex/regfree.o regex/regprefix.o regex/regexport.o replication/logical/decode.o replication/logical/launcher.o replication/logical/logical.o replication/logical/logicalfuncs.o replication/logical/message.o replication/logical/origin.o replication/logical/proto.o replication/logical/relation.o replication/logical/reorderbuffer.o replication/logical/snapbuild.o replication/logical/tablesync.o replication/logical/worker.o replication/walsender.o replication/walreceiverfuncs.o replication/walreceiver.o replication/basebackup.o replication/repl_gram.o replication/slot.o replication/slotfuncs.o replication/syncrep.o replication/syncrep_gram.o rewrite/rewriteRemove.o rewrite/rewriteDefine.o rewrite/rewriteHandler.o rewrite/rewriteManip.o rewrite/rewriteSupport.o rewrite/rowsecurity.o statistics/extended_stats.o statistics/dependencies.o statistics/mcv.o statistics/mvdistinct.o storage/buffer/buf_table.o storage/buffer/buf_init.o storage/buffer/bufmgr.o storage/buffer/freelist.o storage/buffer/localbuf.o storage/file/fd.o storage/file/buffile.o storage/file/copydir.o storage/file/reinit.o storage/file/sharedfileset.o storage/freespace/freespace.o storage/freespace/fsmpage.o storage/freespace/indexfsm.o storage/ipc/barrier.o storage/ipc/dsm_impl.o storage/ipc/dsm.o storage/ipc/ipc.o storage/ipc/ipci.o storage/ipc/latch.o storage/ipc/pmsignal.o storage/ipc/procarray.o storage/ipc/procsignal.o storage/ipc/shmem.o storage/ipc/shmqueue.o storage/ipc/shm_mq.o storage/ipc/shm_toc.o storage/ipc/signalfuncs.o storage/ipc/sinval.o storage/ipc/sinvaladt.o storage/ipc/standby.o storage/large_object/inv_api.o storage/lmgr/lmgr.o storage/lmgr/lock.o storage/lmgr/proc.o storage/lmgr/deadlock.o storage/lmgr/lwlock.o storage/lmgr/lwlocknames.o storage/lmgr/spin.o storage/lmgr/s_lock.o storage/lmgr/predicate.o storage/lmgr/condition_variable.o storage/page/bufpage.o storage/page/checksum.o storage/page/itemptr.o storage/smgr/md.o storage/smgr/smgr.o storage/sync/sync.o tcop/dest.o tcop/fastpath.o tcop/postgres.o tcop/pquery.o tcop/utility.o tsearch/ts_locale.o tsearch/ts_parse.o tsearch/wparser.o tsearch/wparser_def.o tsearch/dict.o tsearch/dict_simple.o tsearch/dict_synonym.o tsearch/dict_thesaurus.o tsearch/dict_ispell.o tsearch/regis.o tsearch/spell.o tsearch/to_tsany.o tsearch/ts_selfuncs.o tsearch/ts_typanalyze.o tsearch/ts_utils.o utils/adt/acl.o utils/adt/amutils.o utils/adt/arrayfuncs.o utils/adt/array_expanded.o utils/adt/array_selfuncs.o utils/adt/array_typanalyze.o utils/adt/array_userfuncs.o utils/adt/arrayutils.o utils/adt/ascii.o utils/adt/bool.o utils/adt/cash.o utils/adt/char.o utils/adt/cryptohashes.o utils/adt/date.o utils/adt/datetime.o utils/adt/datum.o utils/adt/dbsize.o utils/adt/domains.o utils/adt/encode.o utils/adt/enum.o utils/adt/expandeddatum.o utils/adt/expandedrecord.o utils/adt/float.o utils/adt/format_type.o utils/adt/formatting.o utils/adt/genfile.o utils/adt/geo_ops.o utils/adt/geo_selfuncs.o utils/adt/geo_spgist.o utils/adt/inet_cidr_ntop.o utils/adt/inet_net_pton.o utils/adt/int.o utils/adt/int8.o utils/adt/json.o utils/adt/jsonb.o utils/adt/jsonb_gin.o utils/adt/jsonb_op.o utils/adt/jsonb_util.o utils/adt/jsonfuncs.o utils/adt/jsonpath_gram.o utils/adt/jsonpath.o utils/adt/jsonpath_exec.o utils/adt/like.o utils/adt/like_support.o utils/adt/lockfuncs.o utils/adt/mac.o utils/adt/mac8.o utils/adt/misc.o utils/adt/name.o utils/adt/network.o utils/adt/network_gist.o utils/adt/network_selfuncs.o utils/adt/network_spgist.o utils/adt/numeric.o utils/adt/numutils.o utils/adt/oid.o utils/adt/oracle_compat.o utils/adt/orderedsetaggs.o utils/adt/partitionfuncs.o utils/adt/pg_locale.o utils/adt/pg_lsn.o utils/adt/pg_upgrade_support.o utils/adt/pgstatfuncs.o utils/adt/pseudotypes.o utils/adt/quote.o utils/adt/rangetypes.o utils/adt/rangetypes_gist.o utils/adt/rangetypes_selfuncs.o utils/adt/rangetypes_spgist.o utils/adt/rangetypes_typanalyze.o utils/adt/regexp.o utils/adt/regproc.o utils/adt/ri_triggers.o utils/adt/rowtypes.o utils/adt/ruleutils.o utils/adt/selfuncs.o utils/adt/tid.o utils/adt/timestamp.o utils/adt/trigfuncs.o utils/adt/tsginidx.o utils/adt/tsgistidx.o utils/adt/tsquery.o utils/adt/tsquery_cleanup.o utils/adt/tsquery_gist.o utils/adt/tsquery_op.o utils/adt/tsquery_rewrite.o utils/adt/tsquery_util.o utils/adt/tsrank.o utils/adt/tsvector.o utils/adt/tsvector_op.o utils/adt/tsvector_parser.o utils/adt/txid.o utils/adt/uuid.o utils/adt/varbit.o utils/adt/varchar.o utils/adt/varlena.o utils/adt/version.o utils/adt/windowfuncs.o utils/adt/xid.o utils/adt/xml.o utils/cache/attoptcache.o utils/cache/catcache.o utils/cache/evtcache.o utils/cache/inval.o utils/cache/lsyscache.o utils/cache/partcache.o utils/cache/plancache.o utils/cache/relcache.o utils/cache/relmapper.o utils/cache/relfilenodemap.o utils/cache/spccache.o utils/cache/syscache.o utils/cache/ts_cache.o utils/cache/typcache.o utils/error/assert.o utils/error/elog.o utils/fmgr/dfmgr.o utils/fmgr/fmgr.o utils/fmgr/funcapi.o utils/hash/dynahash.o utils/hash/hashfn.o utils/hash/pg_crc.o utils/init/globals.o utils/init/miscinit.o utils/init/postinit.o utils/mb/encnames.o utils/mb/conv.o utils/mb/mbutils.o utils/mb/wchar.o utils/mb/wstrcmp.o utils/mb/wstrncmp.o utils/misc/guc.o utils/misc/help_config.o utils/misc/pg_config.o utils/misc/pg_controldata.o utils/misc/pg_rusage.o utils/misc/ps_status.o utils/misc/queryenvironment.o utils/misc/rls.o utils/misc/sampling.o utils/misc/superuser.o utils/misc/timeout.o utils/misc/tzparser.o utils/mmgr/aset.o utils/mmgr/dsa.o utils/mmgr/freepage.o utils/mmgr/generation.o utils/mmgr/mcxt.o utils/mmgr/memdebug.o utils/mmgr/portalmem.o utils/mmgr/slab.o utils/resowner/resowner.o utils/sort/logtape.o utils/sort/sharedtuplestore.o utils/sort/sortsupport.o utils/sort/tuplesort.o utils/sort/tuplestore.o utils/time/combocid.o utils/time/snapmgr.o utils/fmgrtab.o ../../src/timezone/localtime.o ../../src/timezone/strftime.o ../../src/timezone/pgtz.o jit/jit.o ../../src/port/libpgport_srv.a ../../src/common/libpgcommon_srv.a -L../../src/port -L../../src/common -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags -Wl,-E -lpthread -lrt -lcrypt -ldl -lm -o postgres
As documented by llvm-slicer, I should link the bitcodes together with llvm-link (e.g., llvm-link bitcode1.bc bitcode2.bc ... -o bitcode.bc) to get something like postgres.bc. But I only know how to produce the .bc file for each .c file (via -emit-llvm); and the very-long command above contains many other options (e.g., -lm -L ...) and some .a files, so simply replace .o files with .bc files seems not work.
Question
So I want to know how to get postgres.bc?
Thanks!
Solution: whole-program-llvm.
It provides tools for building whole-program (or whole-library) LLVM bitcode files from an unmodified C or C++ source package. It currently runs on *nix platforms such as Linux, FreeBSD, and Mac OS X.
I'll develop new (external) functions for DB2. My first test:
db2crypt.h
#ifndef DB2CRYPT_H
#define DB2CRYPT_H
#include <string.h>
#include <stdlib.h>
char *encryptAes(const char *source, const char *key);
#endif /* DB2CRYPT_H */
db2crypt.cpp
#include "db2crypt.h"
#include <string>
char *encryptAes(const char *source, const char *key) {
std::string test("abc");
return (char *)test.c_str();
}
is compiled without an error.
g++ -fPIC -c db2crypt.cpp -std=c++14
g++ -shared -o db2crypt db2crypt.o -L$DB2PATH -ldb2
I also copied the new file into $DB2PATH/function and made a softlink in $DB2PATH/function/unfenced.
Then I created the function with
create function aes(VARCHAR(4096), VARCHAR(4096))
SPECIFIC encryptAes
RETURNS VARCHAR(4069)
NOT FENCED
DETERMINISTIC
NO SQL
NO EXTERNAL ACTION
LANGUAGE C
RETURNS NULL ON NULL
INPUT PARAMETER STYLE SQL
EXTERNAL NAME "db2crypt!encryptAes"
which was also ok.
But when I do select db2inst1.aes('a', 'b') from SYSIBM.SYSDUMMY1
I get the error
SQL0444N Die Routine "DB2INST1.AES" (spezifischer Name "ENCRYPTAES") ist
durch Code in Bibliothek oder Pfad ".../sqllib/function/db2crypt", Funktion
"encryptAes" implementiert, auf die kein Zugriff möglich ist. Ursachencode:
"6". SQLSTATE=42724
(sorry, I don't know how to change the error output into english)
What I made wrong?
Ok, I got the answer.
Thank you at #mao, you did help me. But I also needed some other help. If someone searches for an answer:
First you have to compile with some important parameters:
g++ -m64 -fPIC -c <yourfile>.cpp -std=c++14 -I/opt/ibm/db2/V11.1/include/ -D_REENTRANT
g++ -m64 -shared -o <yourfile> <yourfile>.o -L$DB2PATH -ldb2 -Wl,-rpath,$DB2PATH/$LIB -lpthread
Second: The function declaration, you also have to add parameters for null values AND the return value can't be a function return, it has to be a parameter. Also you have to use the types which are defined in sqludf.h:
void SQL_API_FN encryptAes(SQLUDF_CHAR *source,
SQLUDF_CHAR *key,
SQLUDF_CHAR out[4096],
SQLUDF_SMALLINT *sourcenull,
SQLUDF_SMALLINT *keynull,
SQLUDF_SMALLINT *outnull,
SQLUDF_TRAIL_ARGS) {
...
}
Also, when you do C++ instead of C, you have to tell the script that it has to handle the function as C:
#ifdef __cplusplus
extern "C"
#endif
void SQL_API_FN ...
I am trying to run the following example from
Deploy a Perl Application on Windows
with a simple "Hello.pl" (just prints "Hello" to STDOUT).
It fails. The .exe file is created but does not produce any output.
Probably this is my basic misunderstanding. Could you please point me in the right direction? Btw. the "lib folder containing all dependencies" in the project folder is empty since there are no modules in the "hello.pl". Is this a correct assumption?
Thank you very much!
The hello.c file:
#include <EXTERN.h>
#include <perl.h>
EXTERN_C void xs_init (pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_Win32CORE (pTHX_ CV* cv);
EXTERN_C void
xs_init(pTHX)
{
char *file = __FILE__;
dXSUB_SYS;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
newXS("Win32CORE::bootstrap", boot_Win32CORE, file);
}
static PerlInterpreter *my_perl; /*** The Perl interpreter ***/
int main(int argc, char **argv, char **env)
{
argv[1] = "-Ilib";
argv[2] = "hello.pl";
PERL_SYS_INIT3(&argc,&argv,&env);
my_perl = perl_alloc();
perl_construct(my_perl);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}
The perl file to build the compiler command:
#!/perl
use strict;
use warnings FATAL => qw(all);
use ExtUtils::Embed;
print "\nBuilding Hello\n";
my $gcc_cmd = join( ' ' , 'C:\Perl_516_portable\c\bin\gcc -Wall -mwindows -o K:\Scripts\Embed\Hello_3\hello K:\Scripts\Embed\Hello_3\hello.c',
&ccopts, &ldopts );
print STDOUT $gcc_cmd , "\n";
system( $gcc_cmd );
The output:
----------------------------------------------
Perl executable: C:\Perl_516_portable\perl\bin\perl.exe
Perl version : 5.16.3 / MSWin32-x86-multi-thread
C:\Perl_516_portable>perl K:\Scripts\Embed\Hello_3\building_3.pl
Building Hello
C:\Perl_516_portable\c\bin\gcc -Wall -mwindows -o K:\Scripts\Embed\Hello_3\hello K:\Scripts\Embed\Hello_3\hello.c -s -O2 -DWIN32 -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields -I"C:\Perl_516_portable\perl\lib\CORE" -s -L"C:\Perl_516_portable\perl\lib\CORE" -L"C:\Perl_516_portable\c\lib" C:\Perl_516_portable\perl\lib\CORE\libperl516.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libmoldname.a C:Perl_516_portable\c\i686-w64-mingw32\lib\libkernel32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libuser32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libgdi32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libwinspool.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libcomdlg32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libadvapi32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libshell32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libole32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\liboleaut32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libnetapi32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libuuid.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libws2_32.a C:Perl_516_portable\c\i686-w64-mingw32\lib\libmpr.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libwinmm.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libversion.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libodbc32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libodbccp32.a C:\Perl_516_portable\c\i686-w64-mingw32\lib\libcomctl32.a
In file included from C:\Perl_516_portable\perl\lib\CORE/sys/socket.h:180:0,
from C:\Perl_516_portable\perl\lib\CORE/win32.h:356,
from C:\Perl_516_portable\perl\lib\CORE/win32thread.h:4,
from C:\Perl_516_portable\perl\lib\CORE/perl.h:2834,
from K:\Scripts\Embed\Hello_3\hello.c:2:
C:\Perl_516_portable\perl\lib\CORE/win32.h:361:26: warning: "/*" within comment [-Wcomment]
C:\Perl_516_portable\perl\lib\CORE/win32.h:362:33: warning: "/*" within comment [-Wcomment]
In file included from C:\Perl_516_portable\perl\lib\CORE/win32thread.h:4:0,
from C:\Perl_516_portable\perl\lib\CORE/perl.h:2834,
from K:\Scripts\Embed\Hello_3\hello.c:2:
C:\Perl_516_portable\perl\lib\CORE/win32.h:361:26: warning: "/*" within comment [-Wcomment]
C:\Perl_516_portable\perl\lib\CORE/win32.h:362:33: warning: "/*" within comment [-Wcomment]
K:\Scripts\Embed\Hello_3\hello.c: In function 'main':
K:\Scripts\Embed\Hello_3\hello.c:37:1: warning: control reaches end of non-void function [-Wreturn-type]
It will not work if you are in a different path than your script and c files. Remove the absolute paths K:\Scripts\Embed\Hello_3\
The "lib folder containing all dependencies" in the project folder is empty since there are no modules in the "hello.pl". Is this a correct assumption?
If hello.pl does not use any libs, yes.
int main(int argc, char **argv, char **env)
{
argv[1] = "-Ilib";
argv[2] = "hello.pl";
...
This will only work if argc is 2, i.e. you provided 2 args to your hello.exe.
You rather need to check argc and extend argv if < 2, and set argc to 2 if < 2.
Step into the executable with gdb and see what's going wrong. Compile with -g then.
In the long term, the established solution is to use PAR::Dist, or one of the commercial packers. Using the real compiler perlcc on Windows is a bit tricky.
I have installed GTK+- 2.10.14 with directFB backend for my powerpc target board, i could able to run the example application in my target board and see the gui comes up in target LCD.with that i started creating GUI using glade but while working on Glade to create my own GUI i found that glade required gtkbuildet to compile a .glade file. the gtkbuilder is available from version GTK+-2.12.0, so installed again the GTK+-2.12.0 and fallowed procedure say in this tutorial.
My program as follows:
#include<gtk/gtk.h>
int
main( int argc,char **argv )
{
GtkBuilder *builder;
GtkWidget *window;
GError *error = NULL;
/* Init GTK+ */
gtk_init( &argc, &argv );
/* Create new GtkBuilder object */
builder = gtk_builder_new();
/* Load UI from file. If error occurs, report it and quit application.
* * Replace "tut.glade" with your saved project. */
if( ! gtk_builder_add_from_file( builder, "graph.glade", &error ) )
{
g_warning( "%s", error->message );
g_free( error );
return( 1 );
}
/* Get main window pointer from UI */
window = GTK_WIDGET( gtk_builder_get_object( builder, "window1" ) );
/* Connect signals */
gtk_builder_connect_signals( builder, NULL );
/* Destroy builder, since we don't need it anymore */
g_object_unref( G_OBJECT( builder ) );
/* Show window. All other widgets are automatically shown by GtkBuilder */
gtk_widget_show( window );
/* Start main loop */
gtk_main();
return( 0 );
}
Now when I compile the above program I struck up with as error as below:
powerpc-linux-gnu-gcc progressbar.c -o progressbar -pthread -I/opt/gtkdfb/usr/local/include/glib-2.0 -I/opt/gtkdfb/usr/local/lib/glib-2.0/include -I/opt/gtkdfb/usr/local/include/pango-1.0 -I/opt/gtkdfb/usr/local/include/cairo -I/opt/gtkdfb/usr/local/include -I/opt/gtkdfb/usr/local/freetype2 -I/opt/gtkdfb/usr/local/libpng12 -I/opt/gtkdfb/usr/local/includegtk-2.0 -D_REENTRANT -D_GNU_SOURCE -I/opt/gtkdfb/usr/include/directfb -L/opt/gtkdfb/usr/local/lib -ldirectfb -lfusion -ldirect -lpthread -ldl -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lxml2 -lpng12 -lgthread-2.0 -lgtk-directfb-2.0 -lffi -lz -lm `pkg-config gtk+-2.0 --cflags --libs`
/tmp/ccZ9fkFp.o: In function `main':
progressbar.c:(.text+0x3c): undefined reference to `gtk_builder_new'
progressbar.c:(.text+0x58): undefined reference to `gtk_builder_add_from_file'
progressbar.c:(.text+0xb0): undefined reference to `gtk_builder_get_object'
progressbar.c:(.text+0xd8): undefined reference to `gtk_builder_connect_signals'
collect2: ld returned 1 exit status
make: *** [helloworld] Error 1
Please help me to come out of this error.
When there was no GtkBuilder, libglade was used instead. You must use a glade version that supports both GTK+2 and libglade (the 3.8 branch fits the bill).
Do not try to use the directFB back-end on newer GTK+: it was actively maintained by a developer of the Debian installer but it has been abandoned since a long time.
My guess is that pkg-config is still pointing to the old 2.10 version. I also don't understand why you have pkg-config gtk+-2.0 --cflags --libs and also provide all the GCC command line arguments. That is supposed to be the job of pkg-config.
I'm trying to compile an XS into perl [ed(ikegami): which is to say he's using ::MakeMaker's make perl to create a perl with a C vendor library statically linked in ] but when I do, the new version of perl does not support dynamic loading of modules. Any time I try to run perl code that has something like use Socket (or any other module), I get:
Can't load module Socket, dynamic loading not available in this perl.
Is there a compiler/linker switch I'm setting incorrectly or something? All of this was compiled back in 1998 and again in 2004 on a different box (hpux old on PA-RISC), but we're moving to a new box (hpux11 itanium) and I'm hitting the wall.
Here's is my Makefile.PL:
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'Udtutil',
'VERSION_FROM' => 'Udtutil.pm', # finds $VERSION
'LIBS' => '-L/usr/ud/PFUSION/Udtutil -L/usr/ud/lib -lapidummy ' .
'-lshare -ludsql -ludmach -lbasic ' .
'-lperf -lret1 -lides -lpipe -lfunc -lndx -lrep -lshm ' .
'-lmglm -lulc -lglm -ltpmem2 -lcmn ' .
'-llicn -ludus -lunix -lbci -lunirpc -lxmldl -leda ' .
'-lsslU2097e -lcryptoU2097e ' .
'-lodbc -lstd_v2 -lstream -lCsup -lpthread -lm -lcl ' .
'-ldld ' .
'-lnfaclnt -lodsdummy -lcl ' .
'-lCsup -lcl -lelf -lm -lcurses -lsec -lpam ',
'INC' => '-I/usr/ud/include', # e.g., '-I/usr/include/other'
'OPTIMIZE' => '-O -Ae +DD64 -q -z +u4 -w ',
'LINKTYPE' => 'dynamic',
'OBJECT' => '$(BASEEXT)$(OBJ_EXT) funchead.o interfunc.o callcf.o efs_init.o',
);
Here's my .xs file, Udtutil.xs
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "/usr/ud/include/share.h"
#include "/opt/iibase/PFUSION/Udtutil/udtutil.h"
#ifdef __cplusplus
}
#endif
extern int U_IGNSIGSET;
extern int Iflags[2];
#if OS_NT
#define U_backsig(ignsigcnt) { if (((U_IGNSIGSET=(ignsigcnt)) == 0) && (Iflags[0] || Iflags[1])) U_sig_resend(); if (!U_IGNSIGSET && pU_sigflags && U_sigflags) NT_sig_kill(); }
#else
#define U_backsig(ignsigcnt) { if (((U_IGNSIGSET=(ignsigcnt)) == 0) && (Iflags[0] || Iflags[1])) U_sig_resend(); }
#endif
MODULE = Udtutil PACKAGE = Udtutil
int startudt(value1,value2)
int value1
int value2
CODE:
int jmpret, sat;
U_SET_JMP(jmpret,sat);
if (jmpret) {
/* proceed with initialization */
udtcallbasic_init(value1,value2);
RETVAL = 1;
} else {
/* shutdown unibasic and return unsuccessful value */
udtcallbasic_done(1);
RETVAL = 0;
}
OUTPUT:
RETVAL
void stopudt(status)
int status
CODE:
udtcallbasic_done(status);
void calludt(progname, argcount, ...)
char * progname
int argcount
PPCODE:
char * returnval;
int paramspassed = 0;
int status = 0;
char ** arglist = NULL;
int i;
if (argcount + 2 == items) {
/* build the C array from the Perl array */
paramspassed = 1;
arglist = (char **)malloc(argcount);
for (i = 0; i < argcount; i++) {
arglist[i] = (char *)malloc(sv_len(ST(i+2))+1);
strcpy(arglist[i], SvPV(ST(i+2),PL_na));
}
/* make the call into the database */
status = U_callbas(&returnval, progname, argcount, arglist);
for (i = 0; i < argcount; i++) {
free(arglist[i]);
}
free(arglist);
/* EXTEND(sp, 2); */
XPUSHs(sv_2mortal(newSViv(paramspassed)));
XPUSHs(sv_2mortal(newSViv(status)));
if (status == 0) {
/* EXTEND(sp, 1); */
XPUSHs(sv_2mortal(newSVpv(returnval, 0)));
free(returnval);
}
} else {
/* EXTEND(sp, 1); */
XPUSHs(sv_2mortal(newSViv(paramspassed)));
}
When I run perl Makefile.PL, everything looks good:
> perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for Udtutil
Writing MYMETA.yml
When I run make or make perl, everything goes well and it creates a new local perl binary.
However, when I execute ./perl mytest.pl, if mytest.pl *use*s any modules, I get:
Can't load module Socket, dynamic loading not available in this perl.
Any suggestions on how I can compile this new perl and still keep dynamic loading working?
ADDITIONAL INFO:
Here is config data from the old box (the one that works):
> perl -V:usedl
usedl='define';
> perl -V
Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration: Platform:
osname=hpux, osvers=10, archname=PA-RISC2.0
uname='hp-ux autocrft b.10.20 u 9000893 341130351 unlimited-user license '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=y useperlio=undef d_sfio=undef Compiler:
cc='cc', optimize='-O', gccversion=
cppflags='-D_HPUX_SOURCE -Aa'
ccflags ='-D_HPUX_SOURCE -Aa'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries:
ld='ld', ldflags ='-L/usr/local/lib -L/usr/ud/lib'
libpth=/usr/local/lib /usr/lib/pa1.1 /usr/ud/lib /lib /usr/lib /usr/ccs/lib
libs=-lnet -lnsl_s -lndbm -ldld -lm -lc -lndir -lcrypt
libc=/lib/libc.sl, so=sl
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_hpux.xs, dlext=sl, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-B,deferred '
cccdlflags='+z', lddlflags='-b -L/usr/local/lib -L/usr/ud/lib'
Characteristics of this binary (from libperl): Built under hpux
Compiled at May 7 1998 13:59:51 #INC:
/opt/perl5/lib/PA-RISC2.0/5.00404
/opt/perl5/lib
/opt/perl5/lib/site_perl/PA-RISC2.0
/opt/perl5/lib/site_perl
.
...and here is config data from the new box (the one that is not working):
> ./perl -V:usedl
usedl='define';
> ./perl -V
Summary of my perl5 (revision 5 version 14 subversion 2) configuration:
Platform:
osname=hpux, osvers=11.31, archname=IA64.ARCHREV_0-LP64
uname='hp-ux autocrft b.11.31 u ia64 1650208369 unlimited-user license '
config_args=''
hint=previous, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef Compiler:
cc='cc', ccflags ='+DD64 -Ae -D_HPUX_SOURCE -Wl,+vnocompatwarnings -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='+O2 +Onolimit',
cppflags='-Aa -D__STDC_EXT__ -D_HPUX_SOURCE +DD64 -Ae -D_HPUX_SOURCE -Wl,+vnocompatwarnings -I/usr/local/include +DD64 -Ae -D_HPUX_SOURCE -Wl,+vnocompatwarn ings -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
ccversion='B3910B', gccversion='', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=87654321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define Linker and Libraries:
ld='/usr/bin/ld', ldflags =' -L/usr/lib/hpux64'
libpth=/usr/lib/hpux64
libs=-L/usr/lib/hpux64 -lnsl -lnm -ldl -ldld -lm -lsec -lc
perllibs=-lnsl -lnm -ldl -ldld -lm -lsec -lc
libc=/usr/lib/hpux64/libc.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_hpux.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-B,deferred '
cccdlflags='+DD64', lddlflags='-b +vnocompatwarnings'
Characteristics of this binary (from libperl):
Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT
USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF Built under hpux
Compiled at Apr 13 2012 09:27:33
#INC:
/opt/iibase/perl/lib/site_perl/5.14.2/IA64.ARCHREV_0-LP64
/opt/iibase/perl/lib/site_perl/5.14.2
/opt/iibase/perl/lib/5.14.2/IA64.ARCHREV_0-LP64
/opt/iibase/perl/lib/5.14.2
.
I don't know if there is anything useful in this email that I collected and preserved as part of the background information for Perl's DBD::Informix module.
Date: Wed, 13 Aug 1997 13:02:04 -0500 (CDT)
From: "Kent S. Gordon" [email deleted]
Subject: Re: Easy way to force static Informix libraries with DBD:Informix
>> "kgor" == Kent S Gordon <kgor#inetspace.com> wrote:
> Is there a easy way to create a DBD:Informix that uses static Informix
> libraries, but dynamic system libraries for everything else.
I have succeeded in building a perl with DBD:Informix that uses dynamic
loading for everything except DBD:Informix and DBI. I got a runtime error of
not being able to find the symbol of boot_DBI if DBI was also not
statically built into perl. Here is a short discription of what I did.
1) Built perl 5.004_2 normally.
2) Installed perl.
3) Built DBI statically (make static).
4) Installed DBI (make install). This is not just the install of the perl
binary, since DBI.a is needed later.
5) Changed DBD Makefile.pl to call esql -static and esql -static -libs
instead of esql and esql -libs.
6) Created DBD Makefile using perl Makefile.PL.
7) Built DBD statically (make static and make perl, etc.)
8) The make test_static failed, due to wanting to create a dynamic object
(Informix.sl failed due to trying fixup a symbol)
9) Installed with make -k install to get pass error creating Informix.sl,
while still installing Informix.pm (could not find a special install
for static perl.
10) Installed new perl executable. It seems to work after some initial
test.
Kent S. Gordon
Senior Software Engineer
iNetSpace Co.
[Phone and email deleted]
I noted at the time that Kent must be building on HP-UX because of the references to Informix.sl. I think there is nothing useful in here, but it is the only extra information I have on building statically linked versions of Perl. As you can see, it is close to 15 years old.
I wonder if Perl 5.14.x still fully supports and tests statically linked modules?
Don't know if that would be of much help but you can take a look at App::Staticperl. I was able to build DBI and DBD::Informix with it in Solaris, maybe it will work in HP-UX as well.
From perlxstut man page
Dynamic Loading versus Static Loading
It is commonly thought that if a system does not have the capability to dynamically load a library, you cannot build XSUBs. This is incorrect. You can build them, but you must link the XSUBs subroutines with the rest of Perl, creating a new executable. This situation is similar to Perl 4.
This tutorial can still be used on such a system. The XSUB build mechanism will check the system and build a dynamically-loadable library if possible, or else a static library and then, optionally, a new statically-linked executable with that static library linked in.
Should you wish to build a statically-linked executable on a system which can dynamically load libraries, you may, in all the following examples, where the command "make " with no arguments is executed, run the command "make perl " instead.
If you have generated such a statically-linked executable by choice, then instead of saying "make test ", you should say "make test_static ". On systems that cannot build dynamically-loadable libraries at all, simply saying "make test " is sufficient.
It says if you use the line command 'make perl' then you are telling it to build statically.