LLD vs LD Linker Script Discrepancy - ld

I'm moving a project from LD to LLD. An error has cropped up which appears due to the lack of global expression support in LLD. Are variables supported like this?
An simplified example of something that works in LD:
example.ld
_Flash_Origin = 0x01000000;
_App_Length = 16K;
_App_Origin = _Flash_Origin;
MEMORY
{
APP(rx) : ORIGIN = _App_Origin, LENGTH = _App_Length
}
The error is symbol not found: _App_Length. I'm looking for the reason this occurs only in LLD.
The args provided are as follows:
--gc-sections (list of object files...) -Bstatic -L(big path...)clang/10.0.1/lib/baremetal -T example.ld -T sections.ld -o output.elf

Related

Adding neovim to home-manager config leads to permission problem

When adding neovim to my home-manager config (nix on MacOs), like so
programs.neovim = {
enable = true;
package = pkgs.neovim;
viAlias = true;
extraPackages = [
pkgs.rnix-lsp
];
};
I get the following error
these 5 derivations will be built:
/nix/store/7z24wy5ccgjhkw8zc39926z5r0pqfd59-neovim-0.8.0.drv
/nix/store/18kwwzrpsqaa6whyz3shlmidz0lp5sx5-home-manager-fonts.drv
/nix/store/zq40m1z7bl7azgay2gd39c769j5ypszd-home-manager-path.drv
/nix/store/37hvbw396bp6j89grhyqqxb772vbj6j4-activation-script.drv
/nix/store/dghqgkn78cpzq2fwclbg1rkjybwg7dr4-home-manager-generation.drv
building '/nix/store/7z24wy5ccgjhkw8zc39926z5r0pqfd59-neovim-0.8.0.drv'...
/nix/store/lig4bdiwsr9lfb8x8plpnasg95vrw98q-hook/nix-support/setup-hook: line 115: /nix/store/42yqjb325cpgs1gycv3sk9dki1y0qli0-neovim-0.8.0/bin/nvim-python3: Permission denied
error: builder for '/nix/store/7z24wy5ccgjhkw8zc39926z5r0pqfd59-neovim-0.8.0.drv' failed with exit code 1;
last 1 log lines:
> /nix/store/lig4bdiwsr9lfb8x8plpnasg95vrw98q-hook/nix-support/setup-hook: line 115: /nix/store/42yqjb325cpgs1gycv3sk9dki1y0qli0-neovim-0.8.0/bin/nvim-python3: Permission denied
For full logs, run 'nix log /nix/store/7z24wy5ccgjhkw8zc39926z5r0pqfd59-neovim-0.8.0.drv'.
error: 1 dependencies of derivation '/nix/store/18kwwzrpsqaa6whyz3shlmidz0lp5sx5-home-manager-fonts.drv' failed to build
error: 1 dependencies of derivation '/nix/store/zq40m1z7bl7azgay2gd39c769j5ypszd-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/dghqgkn78cpzq2fwclbg1rkjybwg7dr4-home-manager-generation.drv' failed to build
Any ideas what might cause this?
package takes as input an unwrapped version of neovim (without the python/nodeā€¦ wrapper since home-manager does the wrapping itself) as you can see here. Since this value is anyway set by default you can just remove it:
programs.neovim = {
enable = true;
viAlias = true;
extraPackages = [
pkgs.rnix-lsp
];
};

glib-2.72 build fails with during linking to libglib-2.0.so0.7200.0

*The hardware environment I am working in is a QNAP NAS with x86_64 architecture.
The software is a headless, embedded, QNAP-designed Debian-based Gnu/Linux distro based on kernel 4.14.24.
My current issue is in compiling glib-2.72.0, which uses the meson-ninja system, under Python 3.9.
Compilation runs fine
The ninja build fails at
[150/1259] Linking target glib/libglib-2.0.so.0.7200.0
FAILED: glib/libglib-2.0.so.0.7200.0
when, I think, it attempts to link all the *.c.o files listed in the command below:
cc -o glib/libglib-2.0.so.0.7200.0 glib/libglib-2.0.so.0.7200.0.p/deprecated_gallocator.c.o glib/libglib-2.0.so.0.7200.0.p/deprecated_gcache.c.o glib/libglib-2.0.so.0.7200.0.p/deprecated_gcompletion.c.o glib/libglib-2.0.so.0.7200.0.p/deprecated_grel.c.o glib/libglib-2.0.so.0.7200.0.p/deprecated_gthread-deprecated.c.o glib/libglib-2.0.so.0.7200.0.p/garcbox.c.o glib/libglib-2.0.so.0.7200.0.p/garray.c.o glib/libglib-2.0.so.0.7200.0.p/gasyncqueue.c.o glib/libglib-2.0.so.0.7200.0.p/gatomic.c.o glib/libglib-2.0.so.0.7200.0.p/gbacktrace.c.o glib/libglib-2.0.so.0.7200.0.p/gbase64.c.o glib/libglib-2.0.so.0.7200.0.p/gbitlock.c.o glib/libglib-2.0.so.0.7200.0.p/gbookmarkfile.c.o glib/libglib-2.0.so.0.7200.0.p/gbytes.c.o glib/libglib-2.0.so.0.7200.0.p/gcharset.c.o glib/libglib-2.0.so.0.7200.0.p/gchecksum.c.o glib/libglib-2.0.so.0.7200.0.p/gconvert.c.o glib/libglib-2.0.so.0.7200.0.p/gdataset.c.o glib/libglib-2.0.so.0.7200.0.p/gdate.c.o glib/libglib-2.0.so.0.7200.0.p/gdatetime.c.o glib/libglib-2.0.so.0.7200.0.p/gdir.c.o glib/libglib-2.0.so.0.7200.0.p/genviron.c.o glib/libglib-2.0.so.0.7200.0.p/gerror.c.o glib/libglib-2.0.so.0.7200.0.p/gfileutils.c.o glib/libglib-2.0.so.0.7200.0.p/ggettext.c.o glib/libglib-2.0.so.0.7200.0.p/ghash.c.o glib/libglib-2.0.so.0.7200.0.p/ghmac.c.o glib/libglib-2.0.so.0.7200.0.p/ghook.c.o glib/libglib-2.0.so.0.7200.0.p/ghostutils.c.o glib/libglib-2.0.so.0.7200.0.p/giochannel.c.o glib/libglib-2.0.so.0.7200.0.p/gkeyfile.c.o glib/libglib-2.0.so.0.7200.0.p/glib-init.c.o glib/libglib-2.0.so.0.7200.0.p/glib-private.c.o glib/libglib-2.0.so.0.7200.0.p/glist.c.o glib/libglib-2.0.so.0.7200.0.p/gmain.c.o glib/libglib-2.0.so.0.7200.0.p/gmappedfile.c.o glib/libglib-2.0.so.0.7200.0.p/gmarkup.c.o glib/libglib-2.0.so.0.7200.0.p/gmem.c.o glib/libglib-2.0.so.0.7200.0.p/gmessages.c.o glib/libglib-2.0.so.0.7200.0.p/gnode.c.o glib/libglib-2.0.so.0.7200.0.p/goption.c.o glib/libglib-2.0.so.0.7200.0.p/gpattern.c.o glib/libglib-2.0.so.0.7200.0.p/gpoll.c.o glib/libglib-2.0.so.0.7200.0.p/gprimes.c.o glib/libglib-2.0.so.0.7200.0.p/gqsort.c.o glib/libglib-2.0.so.0.7200.0.p/gquark.c.o glib/libglib-2.0.so.0.7200.0.p/gqueue.c.o glib/libglib-2.0.so.0.7200.0.p/grand.c.o glib/libglib-2.0.so.0.7200.0.p/grcbox.c.o glib/libglib-2.0.so.0.7200.0.p/grefcount.c.o glib/libglib-2.0.so.0.7200.0.p/grefstring.c.o glib/libglib-2.0.so.0.7200.0.p/gregex.c.o glib/libglib-2.0.so.0.7200.0.p/gscanner.c.o glib/libglib-2.0.so.0.7200.0.p/gsequence.c.o glib/libglib-2.0.so.0.7200.0.p/gshell.c.o glib/libglib-2.0.so.0.7200.0.p/gslice.c.o glib/libglib-2.0.so.0.7200.0.p/gslist.c.o glib/libglib-2.0.so.0.7200.0.p/gstdio.c.o glib/libglib-2.0.so.0.7200.0.p/gstrfuncs.c.o glib/libglib-2.0.so.0.7200.0.p/gstring.c.o glib/libglib-2.0.so.0.7200.0.p/gstringchunk.c.o glib/libglib-2.0.so.0.7200.0.p/gstrvbuilder.c.o glib/libglib-2.0.so.0.7200.0.p/gtestutils.c.o glib/libglib-2.0.so.0.7200.0.p/gthread.c.o glib/libglib-2.0.so.0.7200.0.p/gthreadpool.c.o glib/libglib-2.0.so.0.7200.0.p/gtimer.c.o glib/libglib-2.0.so.0.7200.0.p/gtimezone.c.o glib/libglib-2.0.so.0.7200.0.p/gtrace.c.o glib/libglib-2.0.so.0.7200.0.p/gtranslit.c.o glib/libglib-2.0.so.0.7200.0.p/gtrashstack.c.o glib/libglib-2.0.so.0.7200.0.p/gtree.c.o glib/libglib-2.0.so.0.7200.0.p/guniprop.c.o glib/libglib-2.0.so.0.7200.0.p/gutf8.c.o glib/libglib-2.0.so.0.7200.0.p/gunibreak.c.o glib/libglib-2.0.so.0.7200.0.p/gunicollate.c.o glib/libglib-2.0.so.0.7200.0.p/gunidecomp.c.o glib/libglib-2.0.so.0.7200.0.p/guri.c.o glib/libglib-2.0.so.0.7200.0.p/gutils.c.o glib/libglib-2.0.so.0.7200.0.p/guuid.c.o glib/libglib-2.0.so.0.7200.0.p/gvariant.c.o glib/libglib-2.0.so.0.7200.0.p/gvariant-core.c.o glib/libglib-2.0.so.0.7200.0.p/gvariant-parser.c.o glib/libglib-2.0.so.0.7200.0.p/gvariant-serialiser.c.o glib/libglib-2.0.so.0.7200.0.p/gvarianttypeinfo.c.o glib/libglib-2.0.so.0.7200.0.p/gvarianttype.c.o glib/libglib-2.0.so.0.7200.0.p/gversion.c.o glib/libglib-2.0.so.0.7200.0.p/gwakeup.c.o glib/libglib-2.0.so.0.7200.0.p/gprintf.c.o glib/libglib-2.0.so.0.7200.0.p/glib-unix.c.o glib/libglib-2.0.so.0.7200.0.p/gspawn.c.o glib/libglib-2.0.so.0.7200.0.p/giounix.c.o glib/libglib-2.0.so.0.7200.0.p/gthread-posix.c.o
-L/opt/lib -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libglib-2.0.so.0 glib/libcharset/libcharset.a subprojects/pcre-8.37/libpcre.a -Wl,-z,nodelete -Wl,-Bsymbolic-functions -pthread -liconv -lm -Wl,--end-group
/opt/bin/ld: glib/libglib-2.0.so.0.7200.0.p/ggettext.c.o: in function `_g_dgettext_should_translate':
/share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:315: undefined reference to `libintl_textdomain'
/opt/bin/ld: /share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:316: undefined reference to `libintl_gettext'
/opt/bin/ld: glib/libglib-2.0.so.0.7200.0.p/ggettext.c.o: in function `ensure_gettext_initialized':
/share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:107: undefined reference to `libintl_bindtextdomain'
/opt/bin/ld: /share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:110: undefined reference to `libintl_bind_textdomain_codeset'
/opt/bin/ld: glib/libglib-2.0.so.0.7200.0.p/ggettext.c.o: in function `g_dgettext':
/share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:402: undefined reference to `libintl_dgettext'
/opt/bin/ld: /share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:402: undefined reference to `libintl_dgettext'
/opt/bin/ld: glib/libglib-2.0.so.0.7200.0.p/ggettext.c.o: in function `g_dcgettext':
/share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:429: undefined reference to `libintl_dcgettext'
/opt/bin/ld: /share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:429: undefined reference to `libintl_dcgettext'
/opt/bin/ld: glib/libglib-2.0.so.0.7200.0.p/ggettext.c.o: in function `g_dngettext':
/share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:460: undefined reference to `libintl_dngettext'
/opt/bin/ld: /share/CACHEDEV1_DATA/jmarks/gdk_files/glib-2.72.0/_build/../glib/ggettext.c:460: undefined reference to `libintl_dngettext'
collect2: error: ld returned 1 exit status
Is this is an issue with gettext?
All the *.c.o files in the failed command exist in the correct directory.
The prefix=/opt
Gettext 0.21 is installed.
gettext.h is located in /opt/share/gettext/ and this path is included in CFLAGS and CPPFLAGS
libintl.a is in opt/lib as is its shared library:
# ldconfig -v |grep libintl
libintl.so.8 -> libintl.so.8.2.0
I would like to learn why this is failing and how to fix it.
Many thanks

Errors in creating Python interface for multiple C++ files in a shared library

I have two c++ files named as "animal.cpp" and "zoo.cpp". These files are compiled as a shared library "zoo.so". I want to access the functions defined in these files from Python interpreter.
However, I am getting errors. I tried to do some changes but getting different kind of errors. I hope expert of Boost-Python may guide me in solving these issues.
Note: To keep the problem simple, I have not used classes, otherwise I could easily make classes of "animal" and "zoo".
I want to access both files function from Python.
Any guidance will be highly appreciated.
Thanks,
animal.cpp
+++++++++++
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string hello_animal() {
return std::string("hello, animal");
}
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string getname_animal() {
std::string input;
std::cout<<"Please enter your favorit animal name: ";
std::getline(std::cin,input);
return std::string("Your favorit animal name is: ").append(input);
}
/*
* This is a macro Boost.Python provides to signify a Python extension module.
*/
BOOST_PYTHON_MODULE(animal) {
// An established convention for using boost.python.
using namespace boost::python;
// Expose the function hello_animal().
def("hello_animal", hello_animal);
// Expose the function getname_animal().
def("getname_animal", getname_animal);
}
zoo.cpp
++++++++
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string hello_zoo() {
return std::string("hello, zoo");
}
/*
* This is the C++ function we write and want to expose to Python.
*/
const std::string getname_zoo() {
std::string input;
std::cout<<"Please enter your favorit zoo name: ";
std::getline(std::cin,input);
return std::string("Your favorit zoo name is: ").append(input);
}
/*
* This is a macro Boost.Python provides to signify a Python extension module.
*/
BOOST_PYTHON_MODULE(zoo) {
// An established convention for using boost.python.
using namespace boost::python;
// Expose the function hello_zoo().
def("hello_zoo", hello_zoo);
// Expose the function getname_zoo().
def("getname_zoo", getname_zoo);
}
I have created a shared library using following command:
g++ -shared -o zoo.so -fPIC zoo.cpp animal.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
Python Interpreter Commands and output:
import zoo
zoo.getname_zoo()
Please enter your favorit zoo name: zoo
'Your favorit zoo name is: zoo'
zoo.getname_animal()
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'getname_animal'
When I make following changes in animal.cpp file, I get different error.
BOOST_PYTHON_MODULE(zoo) {
instead of
BOOST_PYTHON_MODULE(animal) {
On compilation I get following error:
[root#localhost zooexample]# g++ -shared -o zoo.so -fPIC zoo.cpp animal.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
/tmp/cci4WKrP.o: In function initzoo':
animal.cpp:(.text+0x15d): multiple definition ofinitzoo'
/tmp/cctaGDer.o:zoo.cpp:(.text+0x15d): first defined here
/tmp/cci4WKrP.o: In function init_module_zoo()':
animal.cpp:(.text+0x179): multiple definition ofinit_module_zoo()'
/tmp/cctaGDer.o:zoo.cpp:(.text+0x179): first defined here
collect2: error: ld returned 1 exit status
+++++++++++++++++++++++++++++UPDATED++++UPDATED+++++UPDATED+++++++++++++++
Considering the suggestion given by Dan for my previous issue. Now I have created a separate file pyintf.cpp containing the following code:
BOOST_PYTHON_MODULE(pyintf) {
def("hello_zoo", hello_zoo);
def("getname_zoo", getname_zoo);
def("hello_animal", hello_animal);
def("getname_animal", getname_animal);
}
but when I compile and create a shared library using the following command:
g++ -shared -o pyintf.so -fPIC pyintf.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
I get following error when I import the "pyintf" module in python.
import pyintf
Traceback (most recent call last):
File "", line 1, in
ImportError: ./pyintf.so: undefined symbol: _Z9hello_zoov
Can anyone tell what I am not doing correctly?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The issues were resolved by putting all methods which I wanted to expose in a single pyintf.cpp. The errors which I got after update were due to missing header files and source files.
Now, the above issue has resolved by adding header files (zoo.h, animal.h) and source files (zoo.cpp, animal.cpp) in the compilation command. g++ -shared -o pyintf.so -fPIC pyintf.cpp animal.h animal.cpp zoo.h zoo.cpp -lboost_python -lpython2.7 -I/usr/include/python2.7
Thanks Dan for corrections.

Examples of using SCons with knitr

Are there minimal, or even larger, working examples of using SCons and knitr to generate reports from .Rmd files?
kniting an cleaning_session.Rmd file from the command line (bash shell) to derive an .html file, may be done via:
Rscript -e "library(knitr); knit('cleaning_session.Rmd')".
In this example, Rscript and instructions are fed to a Makefile:
RMDFILE=test
html :
Rscript -e "require(knitr); require(markdown); knit('$(RMDFILE).rmd', '$(RMDFILE).md'); markdownToHTML('$(RMDFILE).md', '$(RMDFILE).html', options=c('use_xhtml', 'base64_images')); browseURL(paste('file://', file.path(getwd(),'$(RMDFILE).html'), sep=''
In this answer https://stackoverflow.com/a/10945832/1172302, there is reportedly a solution using SCons. Yet, I did not test enough to make it work for me. Essentially, it would be awesome to have something like the example presented at https://tex.stackexchange.com/a/26573/8272.
[Updated] One working example is an Sconstruct file:
import os
environment = Environment(ENV=os.environ)
# define a `knitr` builder
builder = Builder(action = '/usr/local/bin/knit $SOURCE -o $TARGET',
src_suffix='Rmd')
# add builders as "Knit", "RMD"
environment.Append( BUILDERS = {'Knit' : builder} )
# define an `rmarkdown::render()` builder
builder = Builder(action = '/usr/bin/Rscript -e "rmarkdown::render(input=\'$SOURCE\', output_file=\'$TARGET\')"',
src_suffix='Rmd')
environment.Append( BUILDERS = {'RMD' : builder} )
# define source (and target files -- currently useless, since not defined above!)
# main cleaning session code
environment.RMD(source='cleaning_session.Rmd', target='cleaning_session.html')
# documentation of the Cleaning Process
environment.Knit(source='Cleaning_Process.Rmd', target='Cleaning_Process.html')
# documentation of data
environment.Knit(source='Code_Book.Rmd', target='Code_Book.html')
The first builder calls the custom script called knit. Which, in turn, takes care of the target file/extension, here being cleaning_session.html. Likely the suffix parameter is not needed altogether, in this very example.
The second builder added is Rscript -e "rmarkdown::render(\'$SOURCE\')"'.
The existence of $TARGETs (as in the example at Command wrapper) ensures SCons won't repeat work if a target file already exists.
The custom script (whose source I can't retrieve currently) is:
#!/usr/bin/env Rscript
local({
p = commandArgs(TRUE)
if (length(p) == 0L || any(c('-h', '--help') %in% p)) {
message('usage: knit input [input2 input3] [-n] [-o output output2 output3]
-h, --help to print help messages
-n, --no-convert do not convert tex to pdf, markdown to html, etc
-o output filename(s) for knit()')
q('no')
}
library(knitr)
o = match('-o', p)
if (is.na(o)) output = NA else {
output = tail(p, length(p) - o)
p = head(p, o - 1L)
}
nc = c('-n', '--no-convert')
knit_fun = if (any(nc %in% p)) {
p = setdiff(p, nc)
knit
} else {
if (length(p) == 0L) stop('no input file provided')
if (grepl('\\.(R|S)(nw|tex)$', p[1])) {
function(x, ...) knit2pdf(x, ..., clean = TRUE)
} else {
if (grepl('\\.R(md|markdown)$', p[1])) knit2html else knit
}
}
mapply(knit_fun, p, output = output, MoreArgs = list(envir = globalenv()))
})
The only thing, now, necessary is to run scons.

Unbound Module GWindow

I'm using FREEBSD with Emacs, Tuareg and GTK.
Trying to create my first file but doesn't work.
base.ml:
(* file: base.ml *)
let main () =
let window = GWindow.window () in
window#show ();
GMain.Main.main ()
let _ = main ()
What I type to compile:
ocamlc -I +lablgtk2 -o base lablgtk.cma gtkInit.cmo base.ml
The error I get:
Error: Unbound module GWindow
Can anyone here help me?
This is my makefile:
OCAMLMAKEFILE = ../OCamlMakefile
SOURCES = base.ml
RESULT = base
PACKS = lablgtk2
THREADS = yes
include $(OCAMLMAKEFILE)
Thanks in advance
I guess you are using opam. If it's the case, you can use this compilation command:
$ ocamlc -I +../lablgtk2 -o base lablgtk.cma gtkInit.cmo base.ml