I would like to output an extra variable (i.e. data block with a symbol pointing to it) from a LD script. This variable would contain either constant values, or the offsets and sizes of various other variables in the same section of the output file. In other words, I would like to create a header from a LD script.
I could probably do this with a custom C file referencing symbols defined in the LD script, but I wonder whether it would not be possible to avoid that extra step and do it directly in the LD script. Is it possible?
Finally found a way in LD's documentation: (http://www.math.utah.edu/docs/info/ld_3.html#SEC17)
BYTE(expression)
SHORT(expression)
LONG(expression)
QUAD(expression)
By including one of these four statements in a section definition,
you can explicitly place one, two, four, or eight bytes
(respectively) at the current address of that section. QUAD is only
supported when using a 64 bit host or target. Multiple-byte
quantities are represented in whatever byte order is appropriate for
the output file format (see section BFD).
Question still opened in case there are better answers.
Related
I am fairly new to VMD and programming in general.
I need to combine two pdb files of subunits into a combined pdb and psf file with both subunits.
I used the Namd tutorial and used two pdb files named BChain270VerCTrue.pdb and barn_noH2o_ChainD.pdb and ran this pgn in VMD:
package require psfgen
topology top_all27_prot_lipid.inp
pdbalias residue HIS HSE
pdbalias atom ILE CD1 CD
segment A {pdb BChain270VerCTrue.pdb}
segment D {pdb barn_noH2o_ChainD.pdb}
coordpdb BChain270VerCTrue.pdb A
coordpdb barn_noH2o_ChainD.pdb D
guesscoord
writepdb BarnaseBarnstar270True.pdb
writepsf BarnaseBarnstar270True.psf
However, this creates a sort of mangled pdb that has both subunits covalently bonded. How could I fix this?
This is how the two pdb files look when just used separately in VMD:
This is what the code spits out:
Barnase and barstar are the extracellular ribonuclease and its intracellular inhibitor produced by Bacillus amyloliquefaciens. These two proteins have strong binding energy therefore frequently used for studying protein-protein interaction. To simulate this interaction in silico, We need a proper 1) Forced field, 2) Topology files, and 3) Molecular Dynamic packages like NAMD, Gromacs, or Amber. Plus little bitty understanding of the PDB file format and Structural Biology, and Python or Bash scripting skills.
To generate a topology file one has to generate each component separately, if PDB file has two chains then one has to separate them. However, when we have to put them back we have to follow PDB file format rules. (details can be found at https://www.wwpdb.org/documentation/file-format).
PDB format is composed of many columns but the first column contains the atom information like ATOM, HETATOM, or TER. The last TER designates termination of one chain, without it some software considers them as a single chain like your case.
Make sure two chains are separated TER. you can use a simple text editor to put.
I frequently find myself examining deeply nested data in the variable explorer, e.g.:
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(4)
In order to be descriptive, the variable names are often long. I often want to use some of the data I'm looking at in Matlab expression, composed at the command line. So I end up typing the lengthy series of variable names and indexes. Autocompletion helps, but not much, especially since my variable names share many substrings.
It would be a lifesaver if I could copy into the clipboard the entire expression corresponding to the data being examined in the variable viewer. I haven't yet found a way to do this (the most obvious way being to right-click the tab for the data being examined). So I'm not sure if this functionality exists. Can anyone confirm or deny (hopefully the former) whether this functionality exists? If it does, how is it done?
As an example, suppose you had a class file myClass.m in the current working directory:
% myClass.m
%----------
classdef myClass
properties
structArray1
end % properties
end % class
Now suppose you issued the following commands:
objectName = myClass
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray(1:3)=rand(1,3)
openvar('objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray')
You are now examining a slew of data within a deeply nested data structure. Normally, the data would have been the result of computation other than the rand statement above, and I would have browsed to it manually rather than using the openvar statement above. So I would not normally have readily available the text for the expression
objectName.structArray1(5).structArray2(3).structArray3(7).doubleArray
I have to manually type it in at the command line if I want to use it in a Matlab expression for further computation. It'd be so great if I could somehow point to the tab for that data in the variable explorer and somehow have the expression for the data copied to the clipboard. That way, I can paste it to the command line.
AFTERNOTE:
If there's no way to do this, then as an alternative to manually typing in the whole expression above, is there a way to access the corresponding data object (or a copy thereof) programmatically through the variable explorer window object? This assumes, of course, that the variable explorer is itself a data object as well, through which properties can be accessed. If so, maybe it has a property (perhaps deeply nested) that represents the expression for data in the tab that currently has the focus. If so, I can write a function to retrieve the corresponding data object.
I found that if I undock a tab from the Variables editor, I can select the variable name by double-clicking the variable name in the tab.
Sorry for the ambiguity in wording, but "tab" use to mean the protrusion in the data sheet for displaying the name of the data sheet. Nowadays, "tab" means the whole data sheet. In the first sentence above, I mean the protrusion, which unfortunately doesn't have a distinct name these days (at least none of which I'm aware).
After copying and pasting the variable name from the protrusion, the tab can be docked, which seems to put it back into its original place.
I downloaded some data in DAF "transfer" format, which NASA completely
fails to explain here:
http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/daf.html#Conversion%20and%20Transfer%20of%20DAF%27s
How do I read this file. Here are the first few lines I'm trying to comprehend:
DAFETF NAIF DAF ENCODED TRANSFER FILE
'DAF/SPK '
'2'
'6'
'NIO2SPK '
BEGIN_ARRAY 1 3895604
'URA111 '
'-BC186A96D0E76^8'
'BC0DDF032F041^8'
'2BD'
'7'
'1'
'3'
1024
'-BC18166^8'
'FD2^4'
'-DA4A19AC2BCD18^4'
'-4D5E7E1A67739^4'
'1D46248537C30E^5'
'EBA587DFA5E3B^3'
'-26885CE73CB0D^4'
'-BF0DC6EDB5B2C8^2'
'129C1CFEABE48^3'
'5594FC676368^1'
'-472EBF2225A^1'
'-2198AE1963D^0'
'79CC4CA0C^-1'
'FDD9792D82^-2'
'2001D81A^-2'
'333BCEE2BDD724^4'
'-D78AA10831D9C8^4'
'-6D712677574DF8^4'
'283A14783CDC^4'
'90AC22194ABF6^3'
'-1DEF6219F664FE^3'
'-47318F604096^2'
'9B805F405B1C^1'
'1275B947E2AC^1'
'-16A664664D^0'
'-2F614B9F5^-1'
'-B7C3E41D^-3'
'2F3D71F8^-3'
According to NASA, this is/was a popular format for Fortran programs,
but google was not at all helpful (wikipedia doesn't have an entry
either).
OK, I think I finally figured it out at least part of this. For
reference, the original file (a whopping 162M in size) is the
ura111.bsp file in:
http://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/
and converted to ura111.xsp using the toxfr program in:
http://naif.jpl.nasa.gov/pub/naif/utilities/SunIntel_32bit/
The small files:
http://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/ura111.cmt
http://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/satellites/ura111.inp
explain more about the main file.
Things like "-BC18166^8" really are double precision numbers, written
in modified hexadecimal IEEE-754 format. Wikipedia sort of explains
this format here:
http://en.wikipedia.org/wiki/IEEE-754
and there are IEEE-754-to-decimal convertors like this:
http://www.h-schmidt.net/FloatConverter/ (and many others)
However, these don't explain/convert the exact format NASA uses, which
was one reason for my confusion.
For reference "-BC18166^8" is converted as follows:
The decimal value of "BC18166" is 197230950
We now divide by 16 repeatedly until the result is less than 1 (in
other words, we divide by 16^(length of "BC18166")), yielding
0.734742544591427
The '^8' means we multiply by 16**8 to get 3155695200
the leading "-" just means we add a minus sign to get -3155695200
Of course, we could've combined steps 2 and 3 and just multiplied
197230950 by 16.
#klugerama, to answer your question, yes, I am trying to write a file
parser, this time in Perl, as part of a program that accurately
identifies the positions of various objects in our solar system.
I've already parsed the NASA files relating to planets (and Earth's
own moon) here:
ftp://ssd.jpl.nasa.gov/pub/eph/planets/ascii/
but these are in a much different and far easier-to-parse format.
This document (hosted at ucla.edu) has a complete description of the file format.
Addtionally, check out this python project on Github. It appears to provide the DAFTB function you're looking for.
Edit For the record (cough), it doesn't look like this format was ever intended to be read, per se, by humans. It's a transfer format intended to be converted back to usable binary in whatever executable code is appropriate.
You didn't explain why you want to do this. So unless you are writing a file parser (which has been done already in at least two languages), I'm not sure what the benefit is of being able to read the raw values.
Strictly speaking, the answer to your question is that you use software (see link above) to read it.
I'm dissapointed, because I can't find an information about memory segmentation. I know that I should divide memory into basic sections such as .text, .data, .bss, .stack, that are used in object files of compiled program. I know that there are many more other sections, some are necessary for C and other for C++. I'm searching information about, which sections should be included in linker script?
It depends on your specific compiler and target architecture which output sections will be present or possibly present. And in your code, you can define input sections with arbitrary names. Your linker script serves to bind symbols from files, or symbols listed in explicitly defined input sections, to the output sections.
The best way to find out which output sections are present, is to just compile and link an example application, and inspect the generated map file (if the map file is not automatically generated, you should adjust your linker options). A map file is not meant for consumption by another tool, but serves as a readable description of what goes in your program, on what location, in which section, and why. Note: in that map file you will also find some section names that are not part of your program, and won't translate to physical bits that get executed or used by your program, but are rather aids for your debugger.
When you don't explicitly map some symbols to an output section, the linker will generally just append all remaining symbols after the last explicitly defined section.
You could therefore also define some kind of 'catch-all' section, that will surely attract all not-yet-assigned-symbols, and then verify whether the output section remains empty.
i.e.
At the end of your SECTIONS block, add
SECTION
{
<snip>
.mustbeempty
{
*(.*) ;
}
ASSERT( SIZEOF( .mustbeempty ) = 0 ) ;
}
More info about linker scripts can be found on many places:
On stackoverflow this has been asked before: Which man page describes ld linker script syntax?
A full explanation can be found in this pdf: https://web.eecs.umich.edu/~prabal/teaching/eecs373-f11/readings/Linker.pdf
red hat has nicely formatted pages: https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/index.html
I used this page on scoberlin a lot: http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html since the entire ld file syntax is one full html page so it can easily be searched.
I'm going through Practical Common Lisp, I'm almost finished, and one question that has not been answered for me so far (or maybe I just missed it) is the difference between "require" and "load".
So what is the difference?
Thanks.
require is used for modules, which can each consist of one or many files.
load is used to load an arbitrary single file.
The require function tests whether a
module is already present (using a
case-sensitive comparison); if the
module is not present, require
proceeds to load the appropriate file
or set of files. The pathname
argument, if present, is a single
pathname or a list of pathnames whose
files are to be loaded in order, left
to right. If the pathname argument is
nil or is not provided, the system
will attempt to determine, in some
system-dependent manner, which files
to load. This will typically involve
some central registry of module names
and the associated file lists.
Source: http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node119.html
The load function loads the file named by
filename into the Lisp environment. It
is assumed that a text (character
file) can be automatically
distinguished from an object (binary)
file by some appropriate
implementation-dependent means,
possibly by the file type. The
defaults for filename are taken from
the variable
default-pathname-defaults. If the filename (after the merging in of the
defaults) does not explicitly specify
a type, and both text and object types
of the file are available in the file
system, load should try to select the
more appropriate file by some
implementation-dependent means.
Source: http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node217.html
The difference is that (require) loads a module if it has not been loaded already; (load) loads a file.