Wednesday 14 December 2011

dynamically linked libraries


ELF file format has an RPATH section where it lists hardcoded paths to search for libraries

You can find the RPATH that an application has:
readelf -d app_name  | grep RPATH

Hardcoding paths into an application is not very elegant. It is better to allow the Linux dynamic linker to locate the libraries for you.

Fedora has /etc/ld.so.conf.d/ which is a folder it searches for library paths. You can add foo-x86_64.conf, and inside put the library path, and ld will search that path whenever it needs to locate libfoo.so

Tuesday 13 December 2011

Fedora 16: enable core files

/proc/sys/kernel/core_pattern is used to specify a core dumpfile pattern name.
If the first character of the pattern is a '|', the kernel will treat the rest of the pattern as a command to run. The core dump will be written to the standard input of that program instead of to a file.

The default core_pattern is:
|/usr/libexec/abrt-hook-ccpp %s %c %p %u %g %t e

So we instead put core.%p into the file so we get a core file.
echo "core.%p" > /proc/sys/kernel/core_pattern

put ulimit -c unlimited into your .bashrc

Monday 12 December 2011

Fedora 16: Yum and package management

list installed packages
yum list installed

list available packages (not yet installed)
yum list available

list all packages (installed and available)
yum list all

list all package groups
yum grouplist

list all repost
yum repolist

info on a package
yum info package_name

install a package
yum install package_name

install a package group
yum groupinstall "Group package name"

uninstall a package
yum remove package_name

uninstall a package group

yum groupremove "Group package name"

find installation location of a package
rpm -ql package_name

Sunday 11 December 2011

gcc inline assembler


  1. Register Naming: Register names are prefixed with %, so that registers are %eax, %cl.
  2. Ordering of operands: order of operands is source(s) first, and destination last. mov %edx, %eax" means move contents of edx register to eax
  3. Operand Size: size of memory operands is determined from the last character of the op-code name. The suffix is b for (8-bit) byte, w for (16-bit) word, and l for (32-bit) long. For example, the correct syntax for the above instruction would have been "movl %edx, %eax".
  4. Immediate Operand: Immediate operands are marked with a $ prefix, as in "addl $5, %eax", which means add immediate long value 5 to register %eax).
  5. Memory Operands: Missing operand prefix indicates it is a memory-address; hence "movl $bar, %ebx" puts the address of variable bar into register %ebx, but "movl bar, %ebx" puts the contents of variable bar into register %ebx.
  6. Indexing: Indexing or indirection is done by enclosing the index register or indirection memory cell address in parentheses. For example, "movl 8(%ebp), %eax" (moves the contents at offset 8 from the cell pointed to by %ebp into register %eax).
inline assembler invoked with __asm__("instruction"; "instruction"; "instruction");

__asm__ ("movl %ebx, %eax"); // moves the contents of ebx register to eax
__asm__ ("movb %ch, (%ebx)"); // moves the byte from ch to the memory pointed by ebx
// Add 10 and 20 and store result into register %eax
__asm__ ( "movl $10, %eax;"
          "movl $20, %ebx;"
          "addl %ebx, %eax;" );

Can optionally specify the operands. It allows us to specify the input registers, output registers and a list of clobbered registers.

__asm__ ( "assembly code"
           : output operands                  // optional
           : input operands                   // optional
           : list of clobbered registers );   // optional

If there are no output operands but there are input operands, we must place two consecutive colons surrounding the place where the output operands would go.

It is not mandatory to specify the list of clobbered registers to use, we can leave that to GCC and GCC’s optimization scheme do the needful.


Distilled from here: http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx

More info: http://ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html

Monday 5 December 2011

Fedora 16: yum install c++ programming libraries

sudo yum install

gcc.x86_64
gcc-c++.x86_64
boost.x86_64
boost-devel.x86_64
glibc.x86_64 
glibc-common.x86_64
glibc-debuginfo.x86_64
glibc-debuginfo-common.x86_64
glibc-devel.x86_64
glibc-headers.x86_64
glibc-static.x86_64
glibc-utils.x86_64          

libstdc++.x86_64
libstdc++-devel.x86_64
libstdc++-docs.x86_64
libstdc++-static.x86_64

.bashrc

# colour prompt:
export PS1="\e[0;35m\!\e[m \e[0;36m\u@\h\e[m \e[0;32m\w \$ \e[m"

\e[0;35m<PS1>\e[
  • \e[ Start colour sequence
  • x;y Colour
  • <PS1> prompt sequence
  • \e[m End colour sequence
0;35 = magenta
0;36 = cyan
0;32 = green

\! = history number
\u = user
\h = hostname
\w = full current path

# set xterm title bar

function title()
{
    PREFIX=$@;
    export PROMPT_COMMAND='echo -ne "\033]0;${PREFIX} [${USER}@${HOSTNAME}: ${PWD/$HOME/~}]\007"'
}


export HISTCONTROL=ignoredups

# display a tree of current directory and below...
alias tree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'"


.vimrc

set autoindent
set cindent
set shiftwidth=4
set tabstop=4
set expandtab

" turn off auto indent in order to past code
set pastetoggle=<F2>

" syntax highlighting
colorscheme desert

' enable syntax highlighting in bash vi mode [http://stackoverflow.com/questions/7115324/syntax-highlighting-in-bash-vi-input-mode]
if expand('%:t') =~?'bash-fc-\d\+'
    setfiletype sh
endif

" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" hides buffers instead of closing them (allows opening a new file without writing unsaved changes to current file)
set hidden
" highlight search terms
set hlsearch    
" show search matches as you type
set incsearch

" don't create temporary files
set nobackup
set noswapfile

" remap ';' to ':' - increases the speed of most commands
nnoremap ; :

" clear highlighted search terms by pressing ,/
nmap <silent> ,/ :nohlsearch<CR>

" netrw file explorer - show tree view directory listing style
let g:netrw_liststyle=3

Saturday 3 December 2011

OSX: enable nfs

Turn off automount
add AUTOMOUNT=-NO- to /etc/hostconfig

create mount point in fs
sudo mkdir /mnt/raid

add mount command to /etc/fstab
nas:/mnt/raid /mnt/raid nfs noauto,rw,async


restart

Fedora 16: NFS Server

in /etc/exports, add the path you want to share, and the ip addresss or range you want to give access to, followed by some options

/mnt/raid 192.168.1.0/255.255.255.0(rw,no_subtree_check,async)

rw: read-write access
no_subtree_check: speeds up access by turning off the check that the current folder is a subtree in the same volume
async: speeds up access by turning off synchronous acks

start the requisite services

systemctl start rpcbind.service
systemctl start nfs-server.service
systemctl start nfs-lock.service
systemctl start nfs-idmap.service

enable automatic restart
systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl enable nfs-lock.service
systemctl enable nfs-idmap.service

display exported directories
showmount --exports

Friday 2 December 2011

Fedora 16: Install Squeezebox Server

Obtain repository
rpm -Uvh http://repos.slimdevices.com/yum/squeezecenter/squeezecenter-repo-1-6.noarch.rpm

yum install squeezeboxserver

sudo ln -sf /usr/lib/perl5/vendor_perl/Slim /usr/lib64/perl5/vendor_perl/Slim

yum install perl-CPAN
perl -MCPAN -e'install Log::Log4perl'
perl -MCPAN -e'install CGI::Cookie'

for some reason the CGI::Cookie install failed, go into cpan, and force install it
cpan
force install CGI::Cookie

sudo systemctl start squeezeboxserver.service
sudo systemctl status squeezeboxserver.service

configure it - browse to localhost:9000