This is with bazel 2.2.0 running in a ubuntu 16.04. I've implemented a macro to "build" a C++ library and produce .a and .so files.
def add_cc_lib(lib, SRCS, HDRS, lib_defines, lib_includes, lib_copts, lib_linkopts, archive_libs_deps, additional_deps):
# Define target to create .a for this library
native.cc_library(
name = lib,
srcs = SRCS,
hdrs = HDRS,
deps = archive_libs_deps + additional_deps,
defines = lib_defines,
includes = lib_includes,
copts = lib_copts,
linkopts = lib_linkopts,
linkstatic = 1,
visibility = ["//visibility:public"]
)
# Define target to also create .so for this library
native.cc_binary(
name = "lib" + lib + ".so",
srcs = [":" + lib] + archive_libs_deps,
deps = additional_deps,
defines = lib_defines,
includes = lib_includes,
copts = lib_copts,
linkopts = lib_linkopts,
linkshared = 1,
linkstatic = 1,
visibility = ["//visibility:public"],
)
where archive_libs_deps and additional_deps are list of targets supplied when this add_cc_lib() macro is used to add a C++ library in my repo.
Issue is that, although this produces libfoo.so, it doesn't have any of the symbols from foo.a:
# nm bazel-bin/<path>/libfoo.so
0000000000002008 A __bss_start
0000000000002008 b completed.7594
w __cxa_finalize
0000000000000630 t deregister_tm_clones
00000000000006c0 t __do_global_dtors_aux
0000000000001d40 t __do_global_dtors_aux_fini_array_entry
0000000000002000 d __dso_handle
0000000000001d50 d _DYNAMIC
0000000000002008 A _edata
0000000000002009 A _end
0000000000000730 T _fini
0000000000000700 t frame_dummy
0000000000001d48 t __frame_dummy_init_array_entry
0000000000000780 r __FRAME_END__
0000000000001fd8 d _GLOBAL_OFFSET_TABLE_
w __gmon_start__
00000000000005e0 T _init
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
0000000000001d38 d __JCR_END__
0000000000001d38 d __JCR_LIST__
w _Jv_RegisterClasses
0000000000000670 t register_tm_clones
0000000000002008 d __TMC_END__
0000000000002008 d __TMC_LIST__
I've done quite a bit of searching on the internet and tried out few things without success. Am I missing here something? Any help is much appreciated.
Pass alwayslink = True in the cc_library target.
Related
I've got a Node/ExpressJS server whose client software only has access to the "compress" (LZW) algorithm for de/compression.
As far as I can tell the Node 12.X zlib library does not support LZW. There also don't appear to be any modules in npm that handle LZW in a fast, general way on content larger than a few hundred bytes.
Does anyone know of a way to efficiently and, ideally, natively use LZW on a Node server? Is something in Zlib compatible with LZW? My use case is for data up to a few tens of kilobytes.
Everything is in Docker, so I could install ncompress on the host and use child_process to call it directly, or something, but that seems convoluted.
You could do this without any external library.
These are two LZW encode and decode functions.
function en(c) { var x = "charCodeAt", b, e = {}, f = c.split(""), d
= [], a = f[0], g = 256; for (b = 1; b < f.length; b++) c = f[b], null != e[a + c] ? a += c :(d.push(1 < a.length ? e[a] :ax),
e[a + c] = g, g++, a = c); d.push(1 < a.length ? e[a] :ax);
for (b = 0; b < d.length; b++) d[b] = String.fromCharCode(d[b]);
return d.join(""); }
function de(b) { var a, e = {}, d = b.split(""), c = f = d[0], g = [
c ], h = o = 256; for (b = 1; b < d.length; b++) a =
d[b].charCodeAt(0), a = h > a ? d[b] :e[a] ? e[a] :f + c,
g.push(a), c = a.charAt(0), e[o] = f + c, o++, f = a; return
g.join(""); }
Please note: These functions are for strings only.
Source: https://gist.github.com/JavaScript-Packer/bbf68a4dc0e1fd102221
I am following Scott Klement's tutorials on IFS programming with RPGLE. I am facing the below issues. I have added the code snippets as well. Please assist.
Ownership of object WITHERRH in QTEMP type *MODULE changed.
*SRVPGM object QZDMMDTA in library QSOC not found.
Definition not found for symbol 'QMHSNDPM'.
Definition not found for symbol 'QMHSNDPM'.
Program WITHERRH in library ABCLIBL not created.
The PR were defined inside this copy source.
/if not defined(ERRNO_H)
D strerror PR * extproc('strerror')
D errnum 10I 0 value
/define ERRNO_H
/endif
/if defined(ERRNO_LOAD_PROCEDURE)
P die B
D die PI N
D msg 256A const
D QMHSNDPM PR extproc('QMHSNDPM')
D messageId 7A const
D qualMsgF 20A const
D msgData 256A const
D msgDataLen 10I 0 const
D msgType 10A const
D callSktEnt 10A const
D callSktCnt 10I 0 const
D messageKey 4A
D errorCode 256A
D dsEC DS
D dsECBytesP 1 4I 0 inz(%size(dsEC))
D dsECBytesA 5 8I 0 inz(0)
D dsECMsgId 9 15
D dsECReserv 16 16
D dsECMsgData 17 256
D msgLen S 10I 0
D theKey S 4A
msgLen = %checkr(msg:' ');
if msgLen < 1;
return *off;
endif;
callP QMHSNDPM('CPF9897':'QCPFMSG *LIBL':msg:msgLen:
'*ESCAPE':'*':3:theKey:dsEC);
return *off;
P E
The main program has QC2LE binding directory added; the 'die' procedure is invoked as below,
H dftactgrp(*no) actgrp(*new) bnddir('QC2LE')
D/copy ABCLIBL/QIFSSRC,IFSIO_H
D/copy ABCLIBL/QIFSSRC,ERRNO_H
.....
if write(fd:%addr(wrdata):%size(wrdata)) < 1;
errMsg = %str(strerror(errno));
callP close(fd);
callP die('open(): ' + errMsg);
endif;
As #user2338816 said QMHSNDPM is a external program not a procedure:
D QMHSNDPM PR extpgm('QMHSNDPM')
Most APIs are external programs and not procedures. And when they aren't external programs it's easy to see from the documentation.
For example: Dump Module Variables
With this API you would bind your program to the QTEDMPV service program and then use extproc to reference the procedure.
D DumpVariables PR extproc('QteDumpModuleVariables')
I'd like to identify what assembly GHC produces for a given function.
Here, for example, is some code which (should) rotate bits around in a word - it moves bit 0 to bit 12, bit 12 to 14, bit 14 back to 0 and similarly for the positions 1, 18, 13 and 6.
What's the best way to go about finding the assembly generated for rot0cw in the .S file produced by ghc -O2 -S ...?
I've read this answer, but I don't see any ..._rot0cw_closure in the assembly output.
import Data.Bits
import Data.Int (Int64)
import Text.Printf
import System.Environment
{-# INLINE maskbits #-}
-- set in word v the bits of b corresponding to the mask m
-- assume a bit in b is zero if not in the mask
maskbits v m b = (v .&. (complement m) .|. b)
{-# INLINE tb #-}
-- transfer bit i of word v to bit j of word m; assume bit j of m is 0
tb v i j m = m .|. (rotate (v .&. (bit i)) (j-i))
rot0cw :: Int64 -> Int64
rot0cw v = maskbits (maskbits v m1 b1) m2 b2
where
m1 = 0x0000005005
b1 = tb v 0 2 . tb v 2 14 . tb v 14 12 . tb v 12 0 $ 0
m2 = 0x0000002142
b2 = tb v 1 8 . tb v 8 13 . tb v 13 6 . tb v 6 1 $ 0
showBits v =
let set = [ i | i <- [0..35], testBit v i ]
in "bits set: " ++ (unwords $ map show set)
main = do
(arg0:_) <- getArgs
let v = read arg0
-- let v = 0x0000000005
let v' = rot0cw v
putStrLn $ printf "v = 0x%010x = %12d %s" v v (showBits v)
putStrLn $ printf "v' = 0x%010x = %12d %s" v' v' (showBits v')
I've read this answer, but I don't see any ..._rot0cw_closure in the assembly output.
You need to name your module. e.g. add module Main where at the beginning* to get Main_rot0cw_closure in the generated assembly.
* Strictly speaking, your module needs to export the function.
You will need to export the function rot0cw from your module, otherwise it's effectively dead code. So add something like this to the top of your module:
module Asm(rot0cw) where
The assembly it generates is rather large, if you dump the Cmm -ddump-cmm you can look at each of the proc blocks labeled with the name of the function you're interested in. The basic blocks GHC generates here roughly corresponds to a label in the resulting assembly. So for instance the entry code for rot0cw_closure maps to the following:
cB2:
if (Sp - 32 < SpLim) goto cB4;
Hp = Hp + 16;
if (Hp > HpLim) goto cB6;
I64[Sp - 16] = stg_upd_frame_info;
I64[Sp - 8] = R1;
I64[Hp - 8] = S#_con_info;
I64[Hp + 0] = 0;
I64[Sp - 24] = Hp - 7;
I64[Sp - 32] = stg_ap_p_info;
R2 = $fNumInt64_closure;
Sp = Sp - 32;
jump fromInteger_info; // [R2]
cB4: jump stg_gc_enter_1; // [R1]
cB6:
HpAlloc = 16;
goto cB4;
Which generates out to:
_cB2:
leaq -32(%rbp),%rax
cmpq %r15,%rax
jb _cB4
addq $16,%r12
cmpq 144(%r13),%r12
ja _cB6
movq $stg_upd_frame_info,-16(%rbp)
movq %rbx,-8(%rbp)
movq $S#_con_info,-8(%r12)
movq $0,0(%r12)
leaq -7(%r12),%rax
movq %rax,-24(%rbp)
movq $stg_ap_p_info,-32(%rbp)
movl $$fNumInt64_closure,%r14d
addq $-32,%rbp
jmp fromInteger_info
_cB6:
movq $16,192(%r13)
_cB4:
jmp *-16(%r13)
.size sat_info, .-sat_info
Invariably you'll get a lot of "noise" from all the the GC functions and various runtime calls, and opaque predefined closure objects. But if you really want to dig into the generated looking at the Cmm first is the way to go.
I'd like to know how can I match the external functions called by a binary with their linked shared library.
For example, I can see the functions looking at the .plt section of a disassembled file, and I can find out the used libraries using ldd (or looking at the ELF dynamic section); but how can I match each function with its library?
I followed the Laszio hint and I've created a little python function which get a binary file name and by mixing ldd and nm, returns a dictionary which contains the external functions with their shared libraries.
Maybe it is a little confusing, but it works :)
Here it is the code
def get_dynamicOBJ(filename):
p_nm = subprocess.Popen(["nm", "-D", filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result_nm = p_nm.stdout.readlines()
p_ldd = subprocess.Popen(["ldd", filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result_ldd = p_ldd.stdout.readlines()
dyn = {}
for nm_out in result_nm:
sym_entry = nm_out.split()
if len(sym_entry) >= 2 and sym_entry[0 if len(sym_entry) == 2 else 1] == "U":
sym = sym_entry[1 if len(sym_entry) == 2 else 2]
for lld_out in result_ldd:
lib_entry = lld_out.split()
if "=>" in lld_out and len(lib_entry) > 3: # virtual library
lib = lib_entry[2]
ls_nm = subprocess.Popen(["nm", "-D", lib], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result_lsnm = ls_nm.stdout.readlines()
for ls_nm_out in result_lsnm:
lib_symbol = ls_nm_out.split()
if len(lib_symbol) >= 2 and lib_symbol[0 if len(lib_symbol) == 2 else 1] == "T":
if sym == lib_symbol[1 if len(lib_symbol) == 2 else 2]:
dyn[sym] = lib
return dyn
Is it possible to make a copy of Gdk.image object using lablgtk2 for Ocaml?
I tried to find 'copy' or 'clone' methods but failed.
Maybe you could use pixbuf? It can be created from any drawable.
Here is my clumsy workaround:
let copy_image image =
let w, h = Image.width image, Image.height image in
let copy = Image.create ~kind: `FASTEST ~visual: (Image.get_visual image)
~width: w
~height: h in
for x = 0 to w-1 do
for y = 0 to h-1 do
Image.put_pixel copy ~x:x ~y:y (Image.get_pixel image ~x:x ~y:y)
done
done;
copy