I have a linker script like the one below :
....
.MemSection :
{
_MEM_SEC_BEGIN = . ;
*(.bss .vbss.* .section.*)
*(.common)
_MEM_SEC_END = . ;
} > RAM
_MEM_SEC_END_OUTSIDE = . ;
ASSERT( (_MEM_SEC_END_OUTSIDE == _MEM_SEC_END) , "Warning message" )
ASSERT( (_MEM_SEC_END_OUTSIDE != _MEM_SEC_BEGIN) , "Warning message" )
....
All the names are fictive , but the structure is the same.
The problem is that asserts are failing , I don't know why my location counter is not changing . Please keep in mind that my .MemSection is not empty .
In which situation the location counter could remain the same after an output section definition ?
Thank you !
Related
I am a new Octave user. My Octave version is 4.4.1.
I need help on how to use the parallel package.
I have a function modele_file that takes in as input a class structure that contains the path to files. I have to load that 'mat' files (see the code below).
The problem is that octave indicates that my entry is not defined.
I would be grateful if someone can help me find what is missing in my code
files = dir('./../data/*.mat');
[row col] = size(files);
for k = 1:1000
name{k} = getfield(files, {k,1}, 'name');
end
fun_str = #(stg) strcat("./../data/", stg) ;
vec_name = arrayfun(fun_str, name) ;
vec_result = arrayfun(fun_str, repmat({"result/"}, row,1)) ;
a = [vec_name, vec_result'] ;
struct_info = cell2struct(a, {"name", "result"}, 1);
solution = pararrayfun(nproc, modele_file, struct_info)
Here an example of my function :
function modele = modele_file(info_struct)
file = info_struct{1} ;
path = info_struct{2} ;
load(strcat(file)) ;
modele.X = zeros(2,2) ;
save('file.mat', 'modele') ;
Although my function is able to work. My priority is to launch my function, I do not specifically need it to register in an object.
Thank you.
I'm having trouble coming up with the efficient algorithm that must exist for this problem:
Iterate through an array checking for elements which are "markers". Set a flag if I notice any marker that doesn't divide the rest of the elements into runs of the same length. Except the final run, which is the remainder.
Example that shouldn't set the flag:
*....*....*..*
Examples that should set the flag:
*....*...*...*
*....*....**
Intuition says it should be possible to do online pretty trivially and that it's probably equivalent to some well-known problem whose usual name I don't know.
Solution:
Count the numbers of elements between markers and form a list. Than check if this lists elements are all the same excluding last one and that last element of the list is not 0. Edge case: only one element, it can be 0.
Python code:
def is_correct(string):
splitted_list = string.split("*")[1:-1] # Split and strip edge elements.
if len(splitted_list) == 1:
return True
if len(splitted_list[-1]) == 0: # Check that last element is 0.
return False
for i in range(1, len(splitted_list)-1): # Check that others are the same.
if len(splitted_list[0]) != len(splitted_list[i]):
return False
return True
# Test
print is_correct("*....*....*..*")
print is_correct("*....*...*...*")
print is_correct("*....*....**")
The trick is to first calculate the expected length based on the first *xyz* occurrence. Once this is known we know where to expect the remaining dividers (*). If the divider is encountered out of place it is illegal unless it's part of the remainder.
It's essentially the same logic as in Riko's answer, but with a lot more code as calculating the segment sizes is done inline instead of with string.split.
Below is an example in JavaScript. I tried keeping it as simple as possible by staying away from the more functional aspects of JavaScript. Unfortunately this made it a bit of a wall of code.
var isCorrect = function( str, divider ) {
process.stdout.write( str + ': ' );
// First check the obvious cases. These allow us to skip these checks
// within the loop.
if( str[0] !== divider )
return "Doesn't start with divider";
if( str[ str.length - 1 ] !== divider )
return "Doesnt' end with divider";
// Two variables to hold the state.
// The second variable (divisions) is required only if we want to make
// sure that the last segment is "optimal".
var division = null;
var divisions = 0;
// First find the first divider.
var i = 1;
for( ; i < str.length; i++ ) {
if( str[i] === divider ) {
division = i;
divisions++;
break;
}
}
// Now that we know the division length, make sure the dividers
// are in expected positions.
for( ; i < str.length; i++ ) {
var expectedDivider = ( (i) % division === 0 );
// See if we are expecting a divider.
if( expectedDivider ) {
if( str[i] !== divider )
return "Expected divider at position " + i;
divisions++;
continue;
}
// Since we are not expecting a divider, make sure we don't have one.
if( str[i] === divider ) {
// We had a divider in an unexpected place. This is only allowed for
// the last segment.
if( i < str.length - 1 )
return "Divider not expected at position " + i;
// This is last segment. We could return 'ok' here unless we want
// the optimal segments.
// For optimal segments we want to know whether the last segment
// could have "borrowed" items from the previous ones while still
// remaining smaller than the rest.
// Calculate the bits missing from the last segment.
var offset = ( (i-1) % division );
var missing = division - offset - 1;
if( offset === 0 )
return "Empty division at the end";
// Could the missing bits be taken from the previous divisions?
if( missing > divisions )
return "Last division too short";
// Last segment was OK.
return "ok";
}
}
// All divisions were in expected places:
// Last segment was as long as the rest.
return "ok";
};
The test cases I used:
// Simple cases
// OK
console.log( isCorrect( '*--*--*--*', '*' ) );
console.log( isCorrect( '*---*---*---*', '*' ) );
console.log( isCorrect( '*---*---*--*', '*' ) );
// Middle segment too short.
console.log( isCorrect( '*-----*----*-----*', '*' ) );
// First segment too short
console.log( isCorrect( '*----*-----*-----*', '*' ) );
// "Optimality" tests
// In "optimal" division the segments could be divided to three with
// *----*----*---* so *-----*-----*-* is "unoptimal"
console.log( isCorrect( '*-----*-----*-*', '*' ) );
// These are "optimal"
console.log( isCorrect( '*-----*-----*--*', '*' ) );
console.log( isCorrect( '*-----*-----*---*', '*' ) );
console.log( isCorrect( '*-----*-----*----*', '*' ) );
console.log( isCorrect( '*-----*-----*-----*', '*' ) );
// Last segment too long
console.log( isCorrect( '*-----*-----*------*', '*' ) );
// Last segment empty
console.log( isCorrect( '*--*--*--*--*--**', '*' ) );
I make a program to create an array with the range of my hero :
public function surface($fighterId,$porte_max,$porte_min){
$porte = $porte_max;
$longeur = 0;
$surface;
$i =0;
$coordonne_x=$this->findById($fighterId, array('field'=>'coordinate_x'));
$coordonne_y=$this->findById($fighterId, array('field'=>'coordinate_y'));
for( $for = ($coordonne_y['Fighter']['coordinate_y'] - $porte) ; ($coordonne_y['Fighter']['coordinate_y'] + $porte) ; $for++)
{
for( $for2 = ( $coordonne_x['Fighter']['coordinate_x'] - $longeur) ; ($coordonne_x['Fighter']['coordinate_x'] + $longeur) ; $for2++)
{
$surface[$i] = '[' . $for . '|' . $for2 . ']';
$i++;
}
if ($longeur < $porte)
{
$longeur++ ;
}
else $longeur-- ;
}
return $surface;
}
I don't understand the error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /var/www/html/WebArenaGroupSI4-02-AF/app/Model/Fighter.php on line 36
This is the issue with PHP memory has been exhausted. You can change your PHP memory limit in php.ini. Then restart your server.
Also your code has an endless for, the correct syntax for a for statement is like the following
for(initializationvalue , conditions, updatevalue){
// do your thing here
}
But in your condition, you did not put any conditions but instead did calculation in that.
I am trying to understand how the porting of uboot is done on powerpc mpc8313 processor based board. During this procedure I came across the file called uboot.lds, linker script file.
I need to understand this file. I mean the significance of the contents mentioned and where the actual addresses are defined in uboot package.
for example; in SECTIONS, where I can find the significance of the following information:
/* Read-only sections, merged into text segment: */
. = + SIZEOF_HEADERS;
.interp : { *(.interp) }
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.rel.text : { *(.rel.text) }
.rela.text : { *(.rela.text) }
.rel.data : { *(.rel.data) }
.rela.data : { *(.rela.data) }
.rel.rodata : { *(.rel.rodata) }
.rela.rodata : { *(.rela.rodata) }
.rel.got : { *(.rel.got) }
.rela.got : { *(.rela.got) }
.rel.ctors : { *(.rel.ctors) }
.rela.ctors : { *(.rela.ctors) }
.rel.dtors : { *(.rel.dtors) }
.rela.dtors : { *(.rela.dtors) }
.rel.bss : { *(.rel.bss) }
.rela.bss : { *(.rela.bss) }
.rel.plt : { *(.rel.plt) }
.rela.plt : { *(.rela.plt) }
.init : { *(.init) }
.plt : { *(.plt) }
.text :
{
cpu/mpc83xx/start.o (.text)
*(.text)
*(.fixup)
*(.got1)
. = ALIGN(16);
*(.rodata)
*(.rodata1)
*(.rodata.str1.4)
*(.eh_frame)
}
.fini : { *(.fini) } =0
.ctors : { *(.ctors) }
.dtors : { *(.dtors) }
/* Read-write section, merged into data segment: */
. = (. + 0x0FFF) & 0xFFFFF000;
_erotext = .;
PROVIDE (erotext = .);
.reloc :
{
*(.got)
_GOT2_TABLE_ = .;
*(.got2)
_FIXUP_TABLE_ = .;
*(.fixup)
}
__got2_entries = (_FIXUP_TABLE_ - _GOT2_TABLE_) >> 2;
__fixup_entries = (. - _FIXUP_TABLE_) >> 2;
.data :
{
*(.data)
*(.data1)
*(.sdata)
*(.sdata2)
*(.dynamic)
CONSTRUCTORS
}
_edata = .;
PROVIDE (edata = .);
. = .;
__u_boot_cmd_start = .;
.u_boot_cmd : { *(.u_boot_cmd) }
__u_boot_cmd_end = .;
. = .;
__start___ex_table = .;
__ex_table : { *(__ex_table) }
__stop___ex_table = .;
. = ALIGN(4096);
__init_begin = .;
.text.init : { *(.text.init) }
.data.init : { *(.data.init) }
. = ALIGN(4096);
__init_end = .;
__bss_start = .;
.bss :
{
*(.sbss) *(.scommon)
*(.dynbss)
*(.bss)
*(COMMON)
}
_end = . ;
PROVIDE (end = .);
}
where to look for this information and how to identify the changes to be done in lds file?
Please acknowledge or atleast give some pointers to read the information, thank you
Regads,
Vijay
To port u-boot, the u-boot.lds can probably be used from the cpu directory and not the board directory. In other words, there is probably no need to port this file. However, if there is then here is an overview.
You can find lots of information in the LD documentation.
In general, what LD scripts allow you to do is to override the default places that the GCC tool chain places things in memory when run. When you compile an application, the source code is processed and object code files containing machine code are created. During linking the various object files are combined into one file, ELF executable for example, and a header is placed on the file to tell the OS where each object file should be placed in memory so that it can be found when needed (globals, function calls, etc.)
A custom script is needed if you want to place the code in a specific place that you cannot expect the complier/linker to guess. There are many reasons to do this, as I will try to list.
Constants may be placed in Read-Only memory if RAM is sparse
Memory that is accessed a lot may need to be placed in faster RAM if available
Some data may need to be aligned on a certain boundary, such as 64K
Some code (.TEXT) should be placed at the reset vector so that it is executed at reset
Same for ISR code vectors
Besides this, it can be a way to get convenient access to memory pointers at linkage time. For example, __init_begin is defined as a symbol that has the memory address of any code compiled as *.text.init. You can now call that memory by setting the program counter to the value of __init_begin without having a full C environment configured.
The compiler documentation + u-boot Makefiles should explain how and when the compiler generates object files of each type (ex. .txt, .data, .bss, .fini, .ctors, etc.)
This is a follow up to the question asked here: Groovy parsing text file
The difference now is my file has a header, I attempted to read past the header first and then onto the content that I am wanting, but for some reason it doesn't seem to cooperate.
def dataList = []
def theInfoName = 'testdata.txt'
boolean headersDone = false //header set to false by default
File theInfoFile = new File( theInfoName )
if( !theInfoFile.exists() ) {
println "File does not exist"
} else {
def driveInfo = [:]
// Step through each line in the file
theInfoFile.eachLine { line ->
//this is where im trying to account for the header
if(!headersDone) { //look if line contains "..." if it does that turn headersDone to true
if(line.contains("...")) {
headersDone = true
}
} else {
// If the line isn't blank
if( line.trim() ) {
// Split into a key and value
def (key,value) = line.split( '\t: ' ).collect { it.trim() }
// and store them in the driveInfo Map
driveInfo."$key" = value
}
else {
// If the line is blank, and we have some info
if( driveInfo ) {
// store it in the list
dataList << driveInfo
// and clear it
driveInfo = [:]
}
}
}
// when we've finished the file, store any remaining data
if( driveInfo ) {
dataList << driveInfo
}
}
dataList.eachWithIndex { it, index ->
println "Drive $index"
it.each { k, v ->
println "\t$k = $v"
}
}
I tried it out with the code provided in the previous post to make sure it wasn't something I was doing differently and it came with the same output.
What happens is that it posts the same block of information 11 times.
The header looks is the following:
Random date information here with some other info
Slightly more random information followed by
Examining hard disk information ...
HDD Device 0 : /dev/sda
HDD Model ID : ST3160815A
HDD Serial No : 5RA020QY
HDD Revision : 3.AAA
HDD Size : 152628 MB
Interface : IDE/ATA
Temperature : 33 C
Health : 100%
Performance : 70%
Power on Time : 27 days, 13 hours
Est. Lifetime : more than 1000 days
HDD Device 1 : /dev/sdb
HDD Model ID : TOSHIBA MK1237GSX
HDD Serial No : 97LVF9MHS
HDD Revision : DL130M
HDD Size : 114473 MB
Interface : S-ATA
Temperature : 30 C
Health : 100%
Performance : 100%
Power on Time : 38 days, 11 hours
Est. Lifetime : more than 1000 days
Does anyone know why it is printing out duplicate of the information?
The problem is the addition of the "last" driveInfo to the dataList:
// when we've finished the file, store any remaining data
if( driveInfo ) {
dataList << driveInfo
}
It has to be one curly brace below its current position, otherwise it belongs to the eachLine closure.
Can't see anything obviously wrong with the code. I suggest to add a couple of printlns so you can see how the maps, lists and variables change. That might give you an idea where the bug might be.